There are lot of methods and fields which are supported by string class in .Net. In this article we discuss about all those methods and fields.
string str1 = "string 1";
string str2 = "string 2";
Empty - Public static field representing the empty string.
E.g: String str1 = String.Empty;
Compare() - Overloaded public static method that compares two strings.
E.g:
int i = str1.CompareTo(str2);
CompareOrdinal() - Overloaded public static method that compares two strings without regard to local or culture.
Concat() - Overloaded public static method that creates a new string from one or more strings.
E.g:
string str3 = string.Concat(str1, str2);
Copy() - Overloaded public static method that creates a new string by copying another.
E.g:
string str3 = string.Copy(str1);
Equals() - Overloaded public static method that determines if two strings have the same value.
E.g:
bool bEqual = str1.Equals(str2);
Format() - Overloaded public static method that formats a string using a format specification.
Intern() - Overloaded public static method that returns a reference to the specified instance of a string.
IsInterned() - Overloaded public static method that returns a reference for the string.
Join() - Overloaded public static method that concatenates a specified string between each element of a string array.
Chars() - The string indexer.
Length() - The number of characters in the instance.
Clone() - Returns the string.
Compareto() - Compares this string with another.
CopyTo() - Copies the specified number of characters to an array of Unicode characters.
EndsWith() - Indicates whether the specified string matches the end of this string.
E.g:
bool bVal = str1.EndsWith("str");
Equals() - Determines if two strings have the same value.
Insert() - Returns a new string with the specified string inserted.
E.g:
string str3 = str1.Insert(str1.IndexOf("str"), str2);
LastIndexOf() - Reports the index of the last occurrence of a specified character or string within the string.
PadLeft() - Right-aligns the characters in the string, padding to the left with spaces or a specified character.
PadRight() - Left-aligns the characters in the string, padding to the right with spaces or a specified character.
Remove() - Deletes the specified number of characters.
Split() - Returns the substrings delimited by the specified characters in a string array.
StartsWith() - Indicates if the string starts with the specified characters.
E.g:
bool bVal = str1.StartsWith("str");
SubString() - Retrieves a substring.
ToCharArray() - Copies the characters from the string to a character array.
ToLower() - Returns a copy of the string in lowercase.
ToUpper() - Returns a copy of the string in uppercase.
Trim() - Removes all occurrences of a set of specified characters from beginning and end of the string.
TrimEnd() - Behaves like Trim, but only at the end.
TrimStart() - Behaves like Trim, but only at the start.