...

/

Working with Text: Advanced String Operations

Working with Text: Advanced String Operations

Learn about joining, formatting, and string manipulation with methods and efficiently build strings using StringBuilder for improved performance.

Let’s see the joining, formatting, and other string members and learn how to build strings efficiently.

Joining, formatting, and other string members

There are many other string members, as shown in the following table:

Member

Description

Trim, TrimStart, TrimEnd

These methods trim whitespace characters such as space, tab, and carriage return from the beginning and/or end.

ToUpper, ToLower

These convert all the characters into uppercase or lowercase.

Insert, Remove

These methods insert or remove some text.

Replace

This replaces some text with other text.

string.Empty

This can be used instead of allocating memory each time you use a literal string value using an empty pair of double quotes ("").

string.Concat

This concatenates two string variables. The + operator does the equivalent when used between string operands.

string.Join

This concatenates one or more string variables with a character in between each one.

string.IsNullOrEmpty

This checks whether a string variable is null or empty.

string.IsNullOrWhitespace

This checks whether a string variable is null or whitespace; that is, a mix of any number of horizontal and vertical spacing characters, for example, tab, space, carriage return, line feed, and so on.

string.Format

An alternative method to string interpolation for outputting formatted string values, which uses positioned instead of named parameters.

Note: Some of the preceding methods are static methods. This means that the method can only be called from the type, not from a variable ...