Split String

Purpose

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.

Availability

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

Usage

  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.

    Note

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

    Console.WriteLine("User: admin");
    
  2. Use 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