C# String Methods
Length:
Property that gets the number of characters in the string.
IndexOf(string):
Returns the zero-based index of the first occurrence of a specified
substring. Returns -1 if the substring is not found.
LastIndexOf(string):
Returns the zero-based index of the last occurrence of a specified
substring. Returns -1 if the substring is not found.
Substring(int startIndex):
Returns a substring that starts at a specified index and continues to the
end of the string.
Substring(int startIndex, int length):
Returns a substring that starts at a specified index and has a specified
length.
Replace(string oldValue, string newValue):
Returns a new string in which all occurrences of a specified substring
are replaced with another substring.
Split(char[], StringSplitOptions):
Splits a string into an array of substrings based on the specified
delimiters.
Trim():
Removes all leading and trailing whitespace characters from the string.
TrimStart():
Removes all leading whitespace characters from the string.
TrimEnd():
Removes all trailing whitespace characters from the string.
ToUpper():
Converts all characters in the string to uppercase.
ToLower():
Converts all characters in the string to lowercase.
Contains(string):
Determines whether the string contains a specified substring.
StartsWith(string):
Determines whether the string starts with a specified substring.
EndsWith(string):
Determines whether the string ends with a specified substring.
PadLeft(int totalWidth):
Pads the string on the left with spaces (or a specified character) to
reach the specified total width.
PadRight(int totalWidth):
Pads the string on the right with spaces (or a specified character) to
reach the specified total width.
Insert(int startIndex, string value):
Returns a new string that inserts a specified substring at the specified
index.
Remove(int startIndex):
Returns a new string that removes all characters from the specified
index to the end of the string.
Remove(int startIndex, int count):
Returns a new string that removes a specified number of characters
from the specified index.
ToCharArray():
Converts the string into an array of characters.
Equals(string) (overloaded variants):
Compares the string to another string to determine if they are equal.
Format(string format, object...):
Replaces the format items in a specified string with the string
representation of corresponding objects.
String.Concat(string[]):
Concatenates multiple strings into one string.
String.Join(string separator, string[]):
Concatenates the elements of a string array, using a specified separator
between each element.
IsNullOrEmpty(string):
Determines whether a specified string is either null or an empty string.
IsNullOrWhiteSpace(string):
Determines whether a specified string is null, empty, or consists only of
white-space characters.
GetHashCode():
Returns the hash code for the string, which is useful for hash-based
collections.
Equals(Object):
Determines whether the specified object is equal to the current string.
ToString():
Returns the string representation of the current instance. This method
is implicitly called when the string is used in a context that requires a
string.