JetBrains Rider
 
Get JetBrains Rider
Get your hands on the new features ahead of the release by joining the Early Access Program for Rider 2025.1! Learn more

Introduce Variable for Substring refactoring

Last modified: 11 February 2024

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