Skip to main content

Split String


This Refactoring divides a string into two parts at the caret position or three parts by extracting the selected text. This is helpful when you need to replace a part of a string with a variable.


Available when the caret is within a string literal or a part of a string is selected.


  1. Place the caret into a string literal. You can also divide one string into three concatenated strings by selecting the part you need to separate.


    The blinking cursor shows the caret’s position at which the Refactoring is available.

    Console.WriteLine("User: admin");
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Split String from the menu.

After execution, the Refactoring splits the string into two or three concatenated strings.

Console.WriteLine("User: " + "admin");
See Also