C# Tutorial C# Advanced C# References

C# String Methods



The C# has a number of methods and functions that are available for use with strings. These methods and functions are listed below in alphabetical order. For more details about any one of these, please visit its page.

C# String Methods

MethodDescription
Clone() Make clone of string.
CompareTo() Compare two strings and returns integer value as output. It returns 0 for true and 1 for false.
Contains() The C# Contains method checks whether specified character or string is exists or not in the string value.
EndsWith() Checks whether the string ends with the specified string or not.
Equals() The Equals Method in C# compares two string and returns Boolean value as output.
GetHashCode() This method returns HashValue of specified string.
GetType() It returns the System.Type of current instance.
GetTypeCode() It returns the Stystem.TypeCode for class System.String.
IndexOf() Returns the index position of first occurrence of specified character.
IsNullOrEmpty() Checks whether the specified string is null or empty.
IsNullOrWhiteSpace() Checks whether the specified string is null, empty or contains only whitespaces.
PadLeft() Returns a string that right-aligns the given string by padding with spaces or Unicode character on the left.
PadRight() Returns a string that right-aligns the given string by padding with spaces or Unicode character on the right.
Replace() This method replaces the character.
StartsWith() Checks whether the string starts with the specified string or not.
Substring() Retrieves a substring from a string.
ToCharArray() Converts the character of the string to character array.
ToLower() Converts String into lower case based on rules of the current culture.
ToLowerInvariant() Converts String into lower case based on rules of the invariant culture.
ToString() Converts the value of the instance to a string.
ToUpper() Converts String into Upper case based on rules of the current culture.
ToUpperInvariant() Converts String into Upper case based on rules of the invariant culture.
Trim() Removes all leading and trailing instances of a character(s) / whitespaces from the current string.
TrimEnd() Removes all trailing instances of a character(s) / whitespaces from the current string.
TrimStart() Removes all leading instances of a character(s) / whitespaces from the current string.
Insert() Insert the string or character in the string at the specified position.
IsNormalized() This method checks whether this string is in Unicode normalization form C.
LastIndexOf() Returns the index position of last occurrence of specified character.
Length It is a string property that returns length of string.
Remove() This method deletes all the characters from beginning to specified index position.
Split() This method splits the string based on specified value.