Back to Devexpress

Introduce Format Item

coderushforroslyn-116574-coding-assistance-code-providers-introduce-format-item.md

latest1.2 KB
Original Source

Introduce Format Item

  • Aug 03, 2020

Purpose

Extracts a part of the formatted string into a format item. This Code Provider is especially useful if you used to construct a string first and then replace its parts with the variables.

Availability

Available when a part of the formatted string is selected.

Usage

  1. Select a part of the formatted string.

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

  3. Select Introduce Format Item from the menu.

After execution, the Code Provider creates a string.Format call with the selected part extracted into a format item. If the string is already a format string, the selected part will be added as a new format item to the existing composite formatting method.

csharp
string debugString = string.Format("a: {0}\tb: 2.34\tc: 3.456;", "1.2");
vb
Dim debugString As String = String.Format("a: {0}\tb: 2.34\tc: 3.456;", "1.2")

See Also

Convert to String Interpolation