String Class and Methods
In C#, the string class is used to represent a sequence of characters. It is a reference type and is declared using the keyword “string”.
The string class provides various methods to perform operations on strings. Here are some of the most commonly used methods:
- Length: This method returns the number of characters in the string.
- Concat: This method is used to concatenate two or more strings.
- IndexOf: This method returns the index of the first occurrence of a specified character or substring.
- Substring: This method is used to extract a substring from a string.
- Replace: This method is used to replace all occurrences of a specified character or substring with another string.
- ToUpper and ToLower: These methods are used to convert a string to uppercase or lowercase.
- Trim: This method is used to remove all leading and trailing white spaces from a string.
- Split: This method is used to split a string into an array of substrings based on a specified delimiter.
- Contains: This method returns a boolean value indicating whether a specified substring is present in a string.
- CompareTo: This method is used to compare two strings and returns an integer indicating their relative order.
These are just a few of the many methods available in the string class. The string class and its methods are fundamental to string manipulation in C# and are used extensively in programming.
Apply for C Sharp Certification Now!!
https://www.vskills.in/certification/Certified-C-sharp-Professional