JetBrains Rider
 
Get JetBrains Rider
You are viewing the documentation for an earlier version of JetBrains Rider.

Introduce Variable for Substring refactoring

Last modified: 30 September 2021

This refactoring helps you quickly move a part of a string to a separate variable.

Note that the initial string should not be a type member assignment. The refactoring will create a local variable and therefore it only works where statements are allowed.

Depending on the target C# version, JetBrains Rider either uses interpolated string or String.Format(). Note that you can always convert between those with context actions Alt+Enter.

In the example below, the refactoring creates a variable for a part of the returned phrase:

Introducing variable for substring

Now you can vary this part of the phrase as necessary, for example, move the variable to the method parameter.

Introducing variable for substring