Archive

Posts Tagged ‘Strings’

Refactorings strings in Visual Studio using CodeRush

November 30th, 2011 Comments off

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.

Read more…

Refactorings that work with strings – Use String.Compare

November 30th, 2011 Comments off

The Use String.Compare refactoring shipped in DevExpress Refactor! Pro allows you to convert a usual string equality comparison (==) into a more flexible Compare call on the System.String class. Consider the following code:

Use String.Compare refactoring sample code

Read more…

Refactorings that work with strings – Use Environment.NewLine

November 25th, 2011 Comments off

The Use Environment.NewLine refactoring is one of the simplest refactoring shipped in DevExpress Refactor! Pro which improves code portability. This refactoring replaces the “\r\n” string with the value of the Environment.NewLine property reference. The Environment.NewLine is a static string property from the System namespace that is tied to the current executing environment (platform). It returns a valid “line feed/carriage return” string that corresponds to the current operating system, for example: “\r\n” for Windows platforms, or a string containing just a line feed (“\n“) for Unix platforms.

Read more…

Refactorings that work with strings – Use IsNullOrEmpty

November 25th, 2011 Comments off

When checking that a user has provided a valid input, you will often want to ensure that it is not null or empty. Strings are reference types and can be equal to a null value like any other reference type. Strings can also be empty, meaning their values equal “” and they have zero length. The IsNullOrEmpty call of the System.String class indicates whether the given string is a null or an empty (“”) string. Before this call appeared in the .NET Framework, we were checking strings as follows (for example):

Refactorings - Use IsNullOrEmpty sample code

Read more…

Refactorings for concatenating and splitting strings

November 25th, 2011 Comments off

Concatenation is the process of appending one string to the end of another string. A string is basically a sequence of Unicode characters. An important property of strings is that they are read-only (immutable). Once a string has been created, it cannot be changed. So, when a string is updated, the .NET framework actually discards the original string and creates a new string. In other words, the concatenation of strings is creating an entirely new string, allocating enough memory for everything, copying all the data from the existing values of all concatenated strings and then copying the data from each string. As the string grows, the amount of data it has to copy each time grows too. Having already concatenated strings allows you to avoid such problems.

Read more…

DXCore Services – Strings

November 22nd, 2011 Comments off

The Strings DXCore service manipulates DXCore string providers. It has methods that expand and format string providers for further expansion inside the code editor using the DXCore plug-ins.

Read more…

DXCore Services – String Utilities

September 19th, 2011 Comments off

The String Utilities DXCore service (accessed via the CodeRush.StrUtil object) provides utility methods for manipulating single string, multi-line texts, and string arrays.

Read more…

Refactorings that work with strings – Use StringBuilder

August 31st, 2011 Comments off

In addition to the refactorings that work with the concatenated strings and the String.Format call, there is another useful refactoring called Use StringBuilder. This refactoring replaces the string concatenation operations with corresponding methods of the StringBuilder class.

Read more…