Home > Overview, Refactorings > Refactorings strings in Visual Studio using CodeRush

Refactorings strings in Visual Studio using CodeRush

November 30th, 2011

The String data type of .NET Framework is one of the most often used types when developing software. There are a number of basic operators available for use with strings, such as concatenation and equality comparison. Also the data type is based on a class that includes many powerful methods for string manipulation. Let’s take a brief look at what refactorings shipped in DevExpress Refactor! Pro help us deal with the String data type. You can follow each link, to learn more about a specific refactoring.

Use String.Format

This refactoring converts a composed string expression into a single String.Format call. This refactoring makes string concatenations much more readable and less error prone

Introduce Format Item

This refactoring adds a new format item to the string (e.g., “{0}”, “{1}”) which corresponds to the selected text, and creates a new String.Format call to surround the string if required.

Inline Format Item

This refactoring inlines an existing String.Format argument into the text string, replacing the format item (e.g., “{0}”, “{1}”, etc.) , and creating a concatenated string if required.

Use StringBuilder

This refactoring uses the appropriate Append, Insert, AppendFormat calls of the StringBuilder class when it is applied on a selected piece of strings concatenation code.

Use String.Compare

This refactoring allows you to convert a usual string equality comparison (==) into a more flexible Compare call on the String class.

Use IsNullOrEmpty

This refactoring allows you to convert the string checking code (for null and empty) into the appropriate String.IsNullOrEmpty call.

Concatenate Strings

This refactoring concatenates all selected strings into a single string. A concatenation appends one string to the end of another string.

Split String

This refactoring allows you to break the active string into two or three pieces depending on the editor caret position and the selection state.

Use Environment.NewLine

This refactoring replaces the “\r\n” string with the value of the Environment.NewLineproperty reference.

Products: CodeRush Pro
Versions: 12.1 and up
VS IDEs: any
Updated: Sep/04/2012
ID: R048

Similar Posts: