Tutorial by Examples

The System.String class supports a number of methods to convert between uppercase and lowercase characters in a string. System.String.ToLowerInvariant is used to return a String object converted to lowercase. System.String.ToUpperInvariant is used to return a String object converted to upper...
Using the 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. string s = "Hello World"; bool stringExists = s.Contains("ello"); //stringExists =true as the string contains t...
The System.String.Trim method can be used to remove all leading and trailing white-space characters from a string: string s = " String with spaces at both ends "; s = s.Trim(); // s = "String with spaces at both ends" In addition: To remove white-space only fro...
Using the System.String.Replace method, you can replace part of a string with another string. string s = "Hello World"; s = s.Replace("World", "Universe"); // s = "Hello Universe" All the occurrences of the search string are replaced: string s = "He...
Use the System.String.Split method to return a string array that contains substrings of the original string, split based on a specified delimiter: string sentence = "One Two Three Four"; string[] stringArray = sentence.Split(' '); foreach (string word in stringArray) { Console.W...
The System.String.Join method allows to concatenate all elements in a string array, using a specified separator between each element: string[] words = {"One", "Two", "Three", "Four"}; string singleString = String.Join(",", words); // singleString =...
String Concatenation can be done by using the System.String.Concat method, or (much easier) using the + operator: string first = "Hello "; string second = "World"; string concat = first + second; // concat = "Hello World" concat = String.Concat(first, second); // ...

Page 1 of 1