Back to Devexpress

Convert to String Interpolation

coderushforroslyn-115650-refactoring-assistance-convert-to-string-interpolation.md

latest1.6 KB
Original Source

Convert to String Interpolation

  • Sep 27, 2021

Purpose

Converts a formatted string into string interpolation. Interpolated strings are much easier to read than formatted strings.

Availability

Available when the cursor is on a composed string expression (as shown in the code below) or on the call of one of the following methods, assuming the method argument contains formatted string.

  • String.Format
  • Debug.Print
  • Console.Write
  • Console.WriteLine
  • StringBuilder.AppendFormat

Usage

  1. Place the caret on a composed string expression.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Convert to String Interpolation from the menu.

After execution, Refactoring replaces the composed string to the interpolated string.

csharp
return $"Found record at the position {i}";
vb
Return $"Found record at the position {i}"

Note

This feature is available as a part of Code Cleanup.

See Also

Use String.Format

Use Expression Body

Compress to/Expand Ternary Expression

Split String