System.String Class
Represents a text string. String objects are immutable, meaning their value cannot be changed after creation. Any operation that appears to modify a string actually creates a new string object.
Methods
Compare(string strA, string strB)
Compares two strings, returning a value indicating whether one is less than, equal to, or greater than the other.
- Parameters:
strA: The first string to compare.strB: The second string to compare.
- Returns:
- A signed integer that indicates the lexical relationship between the two strings.
- Less than zero:
strAprecedesstrB. - Zero:
strAandstrBare equal. - Greater than zero:
strAfollowsstrB.
- Less than zero:
CompareTo(string value)
Compares the current string instance to another string.
- Parameters:
value: The string to compare with the current string.
- Returns:
- A signed integer that indicates the lexical relationship between the current string and the
valueparameter.
Contains(char value)
Determines whether the string contains a specified character.
- Parameters:
value: The character to search for.
- Returns:
trueif the string contains the specified character; otherwise,false.
EndsWith(string value)
Determines whether the end of this string instance matches the specified string.
- Parameters:
value: The string to compare with the end of this string.
- Returns:
trueif the character sequence represented byvaluecorresponds to the characters at the end of this string; otherwise,false.
Equals(string value)
Determines whether two strings are equal.
- Parameters:
value: The string to compare to the current string.
- Returns:
trueif the current string andvaluerepresent the same sequence of characters; otherwise,false.
IndexOf(char value)
Reports the zero-based index of the first occurrence of a specified Unicode character within this instance.
- Parameters:
value: The Unicode character to seek.
- Returns:
- The zero-based index of the first occurrence of
valueif found; otherwise, -1.
IsNullOrEmpty(string value)
Indicates whether the specified string is null or an empty string (that is, it contains no characters).
- Parameters:
value: The string to test.
- Returns:
trueif thevalueparameter isnullor an empty string; otherwise,false.
Join(string separator, params string[] values)
Concatenates the elements of a string array, using the specified separator between each element.
- Parameters:
separator: The string to use as a separator.separatoris included in each element of the returned string, except for the first element.values: An array of strings to concatenate.
- Returns:
- A string that consists of the elements of
values, separated byseparator.
Replace(char oldChar, char newChar)
Replaces all occurrences of a specified Unicode character in this instance with another specified Unicode character.
- Parameters:
oldChar: The character to be replaced.newChar: The character that replacesoldChar.
- Returns:
- A new string instance in which all occurrences of
oldCharare replaced withnewChar.
Split(params char[] separator)
Splits this string into substrings by separating it into substrings by the elements of a specified character array.
- Parameters:
separator: A character array that contains one or more characters to use as separators. Ifseparatorisnullor an empty array, the string is split at each character.
- Returns:
- A string array that contains the substrings from this instance, delimited by the characters in
separator. Ifseparatorisnullor an empty array, the substrings are delimited by each character of the string.
StartsWith(string value)
Determines whether the beginning of this string instance matches the specified string.
- Parameters:
value: The string to compare with the beginning of this string.
- Returns:
trueif the characters ofvaluematch the beginning of this string; otherwise,false.
Substring(int startIndex)
Extracts a substring from the current string. The substring starts at a specified character position and continues to the end of the string.
- Parameters:
startIndex: The zero-based starting character position of the substring.
- Returns:
- A string that is equivalent to the substring of the current instance that begins at
startIndexand ends at the last character.
ToLower()
Converts this string to lowercase.
- Returns:
- A string in lowercase.
ToUpper()
Converts this string to uppercase.
- Returns:
- A string in uppercase.
Trim()
Removes all white space characters from the current string.
- Returns:
- A string that has no white space characters from the beginning or end of the current string. If there are no white space characters in the current string, the method returns a reference to the current string.
TrimStart(char trimChar)
Removes all leading occurrences of a specified character from the current string.
- Parameters:
trimChar: The Unicode character to remove.
- Returns:
- A string that remains after all occurrences of
trimCharspecified at the beginning of the current string are removed. If all characters in the current string match thetrimCharparameter, or if the string is empty, the method returns a null reference.