Changing the case of characters within a String
System.String class supports a number of methods to convert between uppercase and lowercase characters in a string.
System.String.ToLowerInvariantis used to return a String object converted to lowercase.
System.String.ToUpperInvariantis used to return a String object converted to uppercase.
Note: The reason to use the invariant versions of these methods is to prevent producing unexpected culture-specific letters. This is explained here in detail.
Concatenate an array of strings into a single string
System.String.Join method allows to concatenate all elements in a string array, using a specified separator between each element:
Finding a string within a string
System.String.Contains you can find out if a particular string exists within a string. The method returns a boolean, true if the string exists else false.
System.String.IndexOf method, you can locate the starting position of a substring within an existing string.
Note the returned position is zero-based, a value of -1 is returned if the substring is not found.
To find the first location from the end of a string, use the
Removing (Trimming) white-space from a string
System.String.Trim method can be used to remove all leading and trailing white-space characters from a string:
To remove white-space only from the beginning of a string use:
To remove white-space only from the end of a string use:
Substring to extract part of a string.
System.String.Substring method can be used to extract a portion of the string.
Replacing a string within a string
System.String.Replace method, you can replace part of a string with another string.
All the occurrences of the search string are replaced:
String.Replace can also be used to remove part of a string, by specifying an empty string as the replacement value:
Splitting a string using a delimiter
System.String.Split method to return a string array that contains substrings of the original string, split based on a specified delimiter:
String Concatenation can be done by using the
System.String.Concat method, or (much easier) using the