String Class and Methods

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:

  1. Length: This method returns the number of characters in the string.
  2. Concat: This method is used to concatenate two or more strings.
  3. IndexOf: This method returns the index of the first occurrence of a specified character or substring.
  4. Substring: This method is used to extract a substring from a string.
  5. Replace: This method is used to replace all occurrences of a specified character or substring with another string.
  6. ToUpper and ToLower: These methods are used to convert a string to uppercase or lowercase.
  7. Trim: This method is used to remove all leading and trailing white spaces from a string.
  8. Split: This method is used to split a string into an array of substrings based on a specified delimiter.
  9. Contains: This method returns a boolean value indicating whether a specified substring is present in a string.
  10. 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.

Share this post
[social_warfare]
Jagged Arrays
Regular Expression and Mutable Strings

Get industry recognized certification – Contact us

keyboard_arrow_up