String Handling Functions
String is an object of String class that represent sequence of characters. We can perform many operations on strings such as concatenation, comparision, getting substring, search, trim, replacement etc using available functions called String handling Functions. The string can be declared by using the keyword string which is an alias for the System.String object. Let us discuss some available string handling functions with its definition.
Function Name | Description |
---|---|
ToUpper() | It is used to convert String into uppercase. |
ToLower() | It is used to convert String into lowercase. |
Substring(int) | The substring starts at a specified character position and continues to the end of the string. |
IndexOf(String) | It is used to find the index value of specified characters. |
Insert(int, String) | It is used to return a new string in which a specified string is inserted at a specified index position. |
Replace(String, String) | It is used to return a new string in which all occurrences of a specified string in the current instance are replaced with another specified string. |
Split(Char) | It is used to split a string into substrings that are based on the characters in an array. |
StartsWith(String) | It is used to check whether the beginning of this string instance matches the specified string. |
Trim() | It is used to remove all leading and trailing white-space characters from the current String object. |
TrimEnd() | It is used to remove all leading and trailing white-space characters in the end of current String object. |
TrimStart() | It is used to remove all leading and trailing white-space characters in the start of current String object. |
Contains(String) | It is used to return a boolean value indicating whether a specified substring occurs within this string. |
CODE
EG 1 . Creating a string and working on some string handling functions.
static void Main(string[] args) {
    string name = "CodersCapsule";
    Console.WriteLine(name.ToUpper()); //Output : CODERSCAPSULE
    Console.WriteLine(name.ToLower()); //Output : coderscapsule
    Console.WriteLine(name.Substring(6)); //Output : Capsule
    Console.WriteLine(name.IndexOf("o")); //Output : 1
    Console.WriteLine(name.Contains("Code")); //Output : True
    Console.WriteLine(name.Replace("C","$")); //Output : $oders$apsule
}
(Click Here, For more exercises)