The String class provides many powerful instance and static methods. These methods are described in this
section. Most of these methods are overloaded, so there are multiple ways that each can be used.
The table below describes many of the instance methods of the String class.
|
Method
|
What It Does
|
|
Clone
|
Returns a reference to the instance of the string.
|
|
CompareTo
|
Compares this string with another.
|
|
CopyTo
|
Copies the specified number of characters from the string
instance to a char array.
|
|
EndsWith
|
Returns true if the specified string matches the end of
the instance string.
|
|
Equals
|
Determines whether the instance string and a specified
string have the same value.
|
|
GetEnumerator
|
Method required to support the IEnumerator
interface (see “Interfaces” later in this chapter).
|
|
IndexOf
|
Reports the index of the first occurrence of a specified
character or string within the instance.
|
|
Insert
|
Returns a new string with the specified string inserted
at the specified position in the current string.
|
|
LastIndexOf
|
Reports the index of the last occurrence of a specified
character or string within the instance.
|
|
PadLeft
|
Returns a new string with the characters in this instance
right-aligned by padding on the left with spaces or a specified character for
a specified total length.
|
|
PadRight
|
Returns a new string with the characters in this instance
left-aligned by padding on the right with spaces or a specified character for
a specified total length.
|
|
Remove
|
Returns a new string that deletes a specified number of
characters from the current instance beginning at a specified position.
|
|
Replace
|
Returns a new string that replaces all occurrences of a
specified character or string in the current instance, with another character
or string.
|
|
Split
|
Identifies the substrings in this instance that are
delimited by one or more characters specified in an array, then places the
substrings into a string array.
|
|
StartsWith
|
Returns true if the specified string matches the
beginning of the instance string.
|
|
Substring
|
Returns a substring from the instance.
|
|
ToCharArray
|
Copies the characters in the instance to a character array.
|
|
ToLower
|
Returns a copy of the instance in lowercase.
|
|
ToUpper
|
Returns a copy of the instance in uppercase.
|
|
Trim
|
Returns a copy of the instance with all occurrences of a
set of specified characters from the beginning and end removed.
|
|
TrimEnd
|
Returns a copy of the instance with all occurrences of a
set of specified characters at the end removed.
|
|
TrimStart
|
Returns a copy of the instance with all occurrences of a
set of specified characters from the beginning removed.
|