C# String Functions And Properties
STRING is another data type in C# programming that represents Unicode characters. It’s a character sequence in which every character is a Unicode character.
Both string and String (Capital S) reveals to be the same in programming structure. A string is just an alias to the System.String. In C#, however, you must use “using System” to access the String. Another distinction is that a string is a reserved keyword, whereas String is a class name. Instead of String, you should always use string.
Let’s have a look at an example:
Source Code-
string str1 = "Hello";
String str2 = "World!";
Console.WriteLine(str1.GetType().FullName);
Console.WriteLine(str2.GetType().FullName);
-------------------------------------------------
Compiler Response-
System.String
System.String
Various C# String Functions-
String Functions | Definitions |
---|---|
Clone() | Create a string clone. |
CompareTo() | When two strings are compared, an integer value is returned as the result. It returns 0 if the condition is true and 1 if the condition is false. |
Contains() | The Contains method in C# determines whether or not a particular character or string exists in the string value. |
EndsWith() | This EndsWith method determines whether or not the provided character is the string’s last character. |
Equals() | In C#, the Equals method compares two strings and returns a Boolean value. |
GetHashCode() | This function returns the string’s HashValue. |
GetType() | The System is returned. The current instance’s type. |
GetTypeCode() | It returns the Stystem.TypeCode for class System.String. |
IndexOf() | The index position of the first occurrence of the provided character is returned. |
ToLower() | Converts a String to lower case using the current culture’s standards. |
ToUpper() | Converts a string to upper case using the current culture’s standards. |
Insert() | At the specified place in the string, insert the string or character. |
IsNormalized() | This method determines whether the string is normalized in Unicode form C. |
LastIndexOf() | The index position of the last occurrence of the provided character is returned. |
Length | The length of a string is returned by this string property. |
Remove() | This method removes all characters from the beginning to the index point supplied. |
Replace() | This method replaces the character. |
Split() | This method splits the string into two halves based on the value supplied. |
StartsWith() | It determines whether the first character of a string matches the character supplied. |
Substring() | This method returns substring. |
ToCharArray() | Converts string into char array. |
Trim() | It removes excess whitespace at the start and end of the string. |