[Serializable] |
An index is the position of a character within a string, and is counted starting from the first character in the string, which is index position zero. That is, a string index is said to be zero-based.
The String(String) constructor is omitted for performance reasons. If you need a copy of a String, consider using String.Copy or the StringBuilder class.
Comparison and search procedures are case-sensitive by default and use the culture associated with the current thread, unless specified otherwise. Uppercase letters evaluate greater than their lowercase equivalents. For more information about the current culture, see the CultureInfo.CurrentCulture topic.
By definition, any String, including the empty string (""), compares greater than null; and two null references compare equal to each other.
Use the String.Compare and String.Equals methods to perform combined reference and value comparisons of Object and String instances. The and relational operators are implemented with the String.Equals method and can also be used to make reference and value comparisons.
The following characters are considered white space when present in a String: hexadecimal 0x9, 0xA, 0xB, 0xC, 0xD, 0x20, 0xA0, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x200B, 0x3000, and 0xFEFF.
The null character is defined as hexadecimal 0x00.
Use the String.Format method to replace each format specification embedded in a parameter string with the formatted string representation of the value of a corresponding object. Format specifications are of the form, { N [, M ][: formatCode ]}, where:
This class implements the IComparable, ICloneable, IConvertible, and IEnumerable interfaces. Use the Convert class for conversions instead of this type's explicit interface member implementation of IConvertible.
| ctor #1 | Overloaded:.ctor(char* value) Initializes a new instance of the String class to the value indicated by a specified pointer to an array of Unicode characters. |
| ctor #2 | Overloaded:.ctor(char[] value) Initializes a new instance of the String class to the value indicated by an array of Unicode characters. |
| ctor #3 | Overloaded:.ctor(sbyte* value) Initializes a new instance of the String class to the value indicated by a pointer to an array of 8-bit signed integers. |
| ctor #4 | Overloaded:.ctor(char c, int count) Initializes a new instance of the String class to the value indicated by a specified Unicode character repeated a specified number of times. |
| ctor #5 | Overloaded:.ctor(char* value, int startIndex, int length) Initializes a new instance of the String class to the value indicated by a specified pointer to an array of Unicode characters, a starting character position within that array, and a length. |
| ctor #6 | Overloaded:.ctor(char[] value, int startIndex, int length) Initializes a new instance of the String class to the value indicated by an array of Unicode characters, a starting character position within that array, and a length. |
| ctor #7 | Overloaded:.ctor(sbyte* value, int startIndex, int length) Initializes a new instance of the String class to the value indicated by a specified pointer to an array of 8-bit signed integers, a starting character position within that array, and a length. |
| ctor #8 | Overloaded:.ctor(sbyte* value, int startIndex, int length, Encoding enc) Initializes a new instance of the String class to the value indicated by a specified pointer to an array of 8-bit signed integers, a starting character position within that array, a length, and an Encoding object. |
| Empty | Represents the empty string. This field is read-only. |
| Chars | Read-only Gets the character at a specified character position in this instance. |
| Length | Read-only Gets the number of characters in this instance. |
| Clone | Returns a reference to this instance of String. |
| Compare | Overloaded:Compare(string strA, string strB) Compares two specified String objects. |
| Compare | Overloaded:Compare(string strA, string strB, bool ignoreCase) Compares two specified String objects, ignoring or honoring their case. |
| Compare | Overloaded:Compare(string strA, string strB, bool ignoreCase, CultureInfo culture) Compares two specified String objects, ignoring or honoring their case, and honoring culture-specific information about their formatting. |
| Compare | Overloaded:Compare(string strA, int indexA, string strB, int indexB, int length) Compares substrings of two specified String objects. |
| Compare | Overloaded:Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase) Compares substrings of two specified String objects, ignoring or honoring their case. |
| Compare | Overloaded:Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase, CultureInfo culture) Compares substrings of two specified String objects, ignoring or honoring their case, and honoring culture-specific information about their formatting. |
| CompareOrdinal | Overloaded:CompareOrdinal(string strA, string strB) Compares two specified String objects, without considering the local national language or culture. |
| CompareOrdinal | Overloaded:CompareOrdinal(string strA, int indexA, string strB, int indexB, int length) Compares substrings of two specified String objects, without considering the local national language or culture. Parameters specify the length and starting positions of the substrings. |
| CompareTo | Overloaded:CompareTo(object value) Compares this instance with a specified Object. |
| CompareTo | Overloaded:CompareTo(string strB) Compares this instance with a specified String object. |
| Concat | Overloaded:Concat(object arg0) Creates the String representation of a specified object. |
| Concat | Overloaded:Concat(params object[] args) Concatenates the String representations of the elements in a specified Object array. |
| Concat | Overloaded:Concat(params string[] values) Concatenates the elements of a specified String array. |
| Concat | Overloaded:Concat(object arg0, object arg1) Concatenates the String representations of two specified objects. |
| Concat | Overloaded:Concat(string str0, string str1) Concatenates two specified instances of String. |
| Concat | Overloaded:Concat(object arg0, object arg1, object arg2) Concatenates the String representations of three specified objects. |
| Concat | Overloaded:Concat(string str0, string str1, string str2) Concatenates three specified instances of String. |
| Concat | Overloaded:Concat Concatenates the String representations of three specified objects and a variable-length parameter list. |
| Concat | Overloaded:Concat(string str0, string str1, string str2, string str3) Concatenates four specified instances of String. |
| Copy | Creates a new instance of String with the same value as a specified String. |
| CopyTo | Copies a specified number of characters from a specified position in this instance to a specified position in an array of Unicode characters. |
| EndsWith | Determines whether the end of this instance matches the specified String. |
| Equals | Overloaded:Equals(object obj)Overridden: Determines whether this instance of String and a specified object, which must be a String, have the same value. |
| Equals | Overloaded:Equals(string value) Determines whether this instance and a specified String have the same value. |
| Equals | Overloaded:Equals(string a, string b) Determines whether two specified String objects have the same value. |
| Format | Overloaded:Format(string format, object arg0) Replaces the format specification in a specified String with the textual equivalent of the value of a specified Object instance. |
| Format | Overloaded:Format(string format, params object[] args) Replaces the format specification in a specified String with the textual equivalent of the value of a corresponding Object instance in a specified array. |
| Format | Overloaded:Format(IFormatProvider provider, string format, params object[] args) Replaces the format specification in a specified String with the textual equivalent of the value of a corresponding Object instance in a specified array. A specified parameter supplies culture-specific formatting information. |
| Format | Overloaded:Format(string format, object arg0, object arg1) Replaces the format specification in a specified String with the textual equivalent of the value of two specified Object instances. |
| Format | Overloaded:Format(string format, object arg0, object arg1, object arg2) Replaces the format specification in a specified String with the textual equivalent of the value of three specified Object instances. |
| GetEnumerator | Retrieves an object that can iterate through the individual characters in this instance. |
| GetHashCode | Overridden: Returns the hash code for this instance. |
| GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
| GetTypeCode | Returns the TypeCode for class String. |
| IndexOf | Overloaded:IndexOf(char value) Reports the index of the first occurrence of the specified Unicode character in this instance. |
| IndexOf | Overloaded:IndexOf(string value) Reports the index of the first occurrence of the specified String in this instance. |
| IndexOf | Overloaded:IndexOf(char value, int startIndex) Reports the index of the first occurrence of the specified Unicode character in this instance. The search starts at a specified character position. |
| IndexOf | Overloaded:IndexOf(string value, int startIndex) Reports the index of the first occurrence of the specified String in this instance. The search starts at a specified character position. |
| IndexOf | Overloaded:IndexOf(char value, int startIndex, int count) Reports the index of the first occurrence of the specified character in this instance. The search starts at a specified character position and examines a specified number of character positions. |
| IndexOf | Overloaded:IndexOf(string value, int startIndex, int count) Reports the index of the first occurrence of the specified String in this instance. The search starts at a specified character position and examines a specified number of character positions. |
| IndexOfAny | Overloaded:IndexOfAny(char[] anyOf) Reports the index of the first occurrence in this instance of any character in a specified array of Unicode characters. |
| IndexOfAny | Overloaded:IndexOfAny(char[] anyOf, int startIndex) Reports the index of the first occurrence in this instance of any character in a specified array of Unicode characters. The search starts at a specified character position. |
| IndexOfAny | Overloaded:IndexOfAny(char[] anyOf, int startIndex, int count) Reports the index of the first occurrence in this instance of any character in a specified array of Unicode characters. The search starts at a specified character position and examines a specified number of character positions. |
| Insert | Inserts a specified instance of String at a specified index position in this instance. |
| Intern | Retrieves the system's reference to the specified String. |
| IsInterned | Retrieves a reference to a specified String. |
| Join | Overloaded:Join(string separator, string[] value) Concatenates a specified separator String between each element of a specified String array, yielding a single concatenated string. |
| Join | Overloaded:Join(string separator, string[] value, int startIndex, int count) Concatenates a specified separator String between each element of a specified String array, yielding a single concatenated string. Parameters specify the first array element and number of elements to use. |
| LastIndexOf | Overloaded:LastIndexOf(char value) Reports the index position of the last occurrence of a specified Unicode character within this instance. |
| LastIndexOf | Overloaded:LastIndexOf(string value) Reports the index position of the last occurrence of a specified String within this instance. |
| LastIndexOf | Overloaded:LastIndexOf(char value, int startIndex) Reports the index position of the last occurrence of a specified Unicode character within this instance. The search starts at a specified character position. |
| LastIndexOf | Overloaded:LastIndexOf(string value, int startIndex) Reports the index position of the last occurrence of a specified String within this instance. The search starts at a specified character position. |
| LastIndexOf | Overloaded:LastIndexOf(char value, int startIndex, int count) Reports the index position of the last occurrence of the specified Unicode character in a substring within this instance. The search starts at a specified character position and examines a specified number of character positions. |
| LastIndexOf | Overloaded:LastIndexOf(string value, int startIndex, int count) Reports the index position of the last occurrence of a specified String within this instance. The search starts at a specified character position and examines a specified number of character positions. |
| LastIndexOfAny | Overloaded:LastIndexOfAny(char[] anyOf) Reports the index position of the last occurrence in this instance of one or more characters specified in a Unicode array. |
| LastIndexOfAny | Overloaded:LastIndexOfAny(char[] anyOf, int startIndex) Reports the index position of the last occurrence in this instance of one or more characters specified in a Unicode array. The search starts at a specified character position. |
| LastIndexOfAny | Overloaded:LastIndexOfAny(char[] anyOf, int startIndex, int count) Reports the index position of the last occurrence in this instance of one or more characters specified in a Unicode array. The search starts at a specified character position and examines a specified number of character positions. |
| PadLeft | Overloaded:PadLeft(int totalWidth) Right-aligns the characters in this instance, padding with spaces on the left for a specified total length. |
| PadLeft | Overloaded:PadLeft(int totalWidth, char paddingChar) Right-aligns the characters in this instance, padding on the left with a specified Unicode character for a specified total length. |
| PadRight | Overloaded:PadRight(int totalWidth) Left-aligns the characters in this string, padding with spaces on the right, for a specified total length. |
| PadRight | Overloaded:PadRight(int totalWidth, char paddingChar) Left-aligns the characters in this string, padding on the right with a specified Unicode character, for a specified total length. |
| Remove | Deletes a specified number of characters from this instance beginning at a specified position. |
| Replace | Overloaded:Replace(char oldChar, char newChar) Replaces all occurrences of a specified Unicode character in this instance with another specified Unicode character. |
| Replace | Overloaded:Replace(string oldValue, string newValue) Replaces all occurrences of a specified String in this instance, with another specified String. |
| Split | Overloaded:Split(params char[] separator) 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. |
| Split | Overloaded:Split(char[] separator, int count) 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. A parameter specifies the maximum number of array elements to return. |
| StartsWith | Determines whether the beginning of this instance matches the specified String. |
| Substring | Overloaded:Substring(int startIndex) Retrieves a substring from this instance. The substring starts at a specified character position. |
| Substring | Overloaded:Substring(int startIndex, int length) Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length. |
| ToCharArray | Overloaded:ToCharArray() Copies the characters in this instance to a Unicode character array. |
| ToCharArray | Overloaded:ToCharArray(int startIndex, int length) Copies the characters in a specified substring in this instance to a Unicode character array. |
| ToLower | Overloaded:ToLower() Returns a copy of this String in lowercase. |
| ToLower | Overloaded:ToLower(CultureInfo culture) Returns a copy of this String in lowercase, taking into account specified culture-specific information. |
| ToString | Overloaded:ToString()Overridden: Returns this instance of String; no actual conversion is performed. |
| ToString | Overloaded:ToString(IFormatProvider provider) Returns this instance of String; no actual conversion is performed. |
| ToUpper | Overloaded:ToUpper() Returns a copy of this String in uppercase, using default properties. |
| ToUpper | Overloaded:ToUpper(CultureInfo culture) Returns a copy of this String in uppercase, taking into account culture-specific information. |
| Trim | Overloaded:Trim() Removes all occurrences of white space characters from the beginning and end of this instance. |
| Trim | Overloaded:Trim(params char[] trimChars) Removes all occurrences of a set of characters specified in a Unicode character array from the beginning and end of this instance. |
| TrimEnd | Removes all occurrences of a set of characters specified in a Unicode character array from the end of this instance. |
| TrimStart | Removes all occurrences of a set of characters specified in a Unicode character array from the beginning of this instance. |
| op_Equality | Determines whether two specified String objects have the same value. |
| op_Inequality | Determines whether two specified String objects have different values. |
| Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
| MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
[CLSCompliant(false)] |
value
This constructor copies the sequence of Unicode charaters at the specified pointer until a null character (hexadecimal 0x00) is reached.
If the specified array is not null-terminated, the behavior of this constructor is system dependent. For example, such a situation might cause an access violation.
In C#, this constructor is defined only in the context of unmanaged code.
public String( |
value
[CLSCompliant(false)] |
value
This constructor copies the sequence of charaters at the specified pointer until a null character (hexadecimal 0x00) is reached.
If the specified array is not null-terminated, the behavior of this constructor is system dependent. For example, such a situation might cause an access violation.
In C#, this constructor is defined only in the context of unmanaged code.
c
count
| Exception Type | Condition |
|---|---|
| ArgumentOutOfRangeException | count is less than zero. |
value
startIndex
length
| Exception Type | Condition |
|---|---|
| ArgumentOutOfRangeException | startIndex or length is less than zero. -or- value is a null pointer and length is not zero. |
This constructor copies Unicode characters from value, starting at startIndex and ending at (startIndex + length - 1).
If the specified range is outside of the memory allocated for the sequence of characters, the behavior of this constructor is system dependent. For example, such a situation might cause an access violation.
In C#, this constructor is defined only in the context of unmanaged code.
value
startIndex
length
| Exception Type | Condition |
|---|---|
| ArgumentNullException | value is null, and startIndex and length are not zero. |
| ArgumentOutOfRangeException | startIndex or length is less than zero. -or- The sum of startIndex and length is greater than the number of elements in value. |
This constructor copies Unicode characters from value, starting at startIndex and ending at (startIndex + length - 1).
value
startIndex
length
| Exception Type | Condition |
|---|---|
| ArgumentOutOfRangeException | startIndex or length is less than zero. -or- value is a null pointer and length is not zero. |
This constructor copies Unicode characters from value, starting at startIndex and ending at (startIndex + length - 1).
If the specified range is outside of the memory allocated for the sequence of characters, the behavior of this constructor is system dependent. For example, such a situation might cause an access violation.
In C#, this constructor is defined only in the context of unmanaged code.
[CLSCompliant(false)] |
value
startIndex
length
enc
| Exception Type | Condition |
|---|---|
| ArgumentOutOfRangeException | startIndex or length is less than zero. |
public static readonly string Empty;
|
No member name
public char this[int index] {get;}
|
index
| Exception Type | Condition |
|---|---|
| IndexOutOfRangeException | index is greater than or equal to the length of this object or less than zero. |
public int Length {get;}
|
public object Clone(); |
strA
strB
| Value | Meaning |
|---|---|
| Less than zero | is less than . |
| Zero | equals . |
| Greater than zero | is greater than . |
This method performs a case-sensitive operation. The method uses the current culture to determine the ordering of individual characters. Uppercase letters evaluate greater than their lowercase equivalents. The two strings are compared on a character-by-character basis.
strA
strB
ignoreCase
| Value | Meaning |
|---|---|
| Less than zero | is less than . |
| Zero | equals . |
| Greater than zero | is greater than . |
This method uses the current culture to determine the ordering of individual characters. The two strings are compared on a character-by-character basis.
public static int Compare( |
strA
strB
ignoreCase
culture
| Value | Meaning |
|---|---|
| Less than zero | is less than . |
| Zero | equals . |
| Greater than zero | is greater than . |
| Exception Type | Condition |
|---|---|
| ArgumentNullException | culture is null. |
By definition, any String, including the empty string, compares greater than a null reference; and two null references compare equal to each other.
public static int Compare( |
strA
indexA
strB
indexB
length
| Value | Meaning |
|---|---|
| Less than zero | The substring in is less than the substring in . |
| Zero | The substrings are equal, or is zero. |
| Greater than zero | The substring in is greater than the substring in . |
| Exception Type | Condition |
|---|---|
| ArgumentOutOfRangeException | The sum of indexA and length is greater than strA.Length. -or- The sum of indexB and length is greater than strB.Length. -or- indexA, indexB, or length is negative. |
length cannot be negative. If length is zero, then zero is returned.
The number of characters compared is the lesser of the length of strA less indexA, the length of strB less indexB, and length.
By definition, any String, including the empty string, compares greater than null; and two null references compare equal to each other.
This method performs a case-sensitive operation. The method uses the current culture to determine the ordering of individual characters. Uppercase letters evaluate greater than their lowercase equivalents. The two strings are compared on a character-by-character basis.
public static int Compare( |
strA
indexA
strB
indexB
length
ignoreCase
| Value Type | Condition |
|---|---|
| Less than zero | The substring in is less than the substring in . |
| Zero | The substrings are equal, or is zero. |
| Greater than zero | The substring in is greater than the substring in . |
| Exception Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Either index is outside the series of characters to be compared. -or- length is negative. |
The number of characters compared is the lesser of the length of strA less indexA, the length of strB less indexB, and length.
By definition, any String, including the empty string, compares greater than null; and two null references compare equal to each other.
This method uses the current culture to determine the ordering of individual characters. The two strings are compared on a character-by-character basis.
public static int Compare( |
strA
indexA
strB
indexB
length
ignoreCase
culture
| Value Type | Condition |
|---|---|
| Less than zero | The substring in is less than the substring in . |
| Zero | The substrings are equal, or is zero. |
| Greater than zero | The substring in is greater than the substring in . |
| Exception Type | Condition |
|---|---|
| ArgumentNullException | culture is null. |
| ArgumentOutOfRangeException | Either index is outside the series of characters to be compared. -or- length is negative. |
The number of characters compared is the lesser of the length of strA less indexA, the length of strB less indexB, and length.
By definition, any String, including the empty string, compares greater than a null reference; and two null references compare equal to each other.
strA
strB
| Permission | Description |
|---|---|
| Less than zero | is less than . |
| Zero | and are equal. |
| Greater than zero | is greater than . |
public static int CompareOrdinal( |
strA
indexA
strB
indexB
length
| Value Type | Condition |
|---|---|
| Less than zero | The substring in is less than the substring in . |
| Zero | The substrings are equal, or is zero. |
| Greater than zero | The substring in is greater than the substring in . |
| Exception Type | Condition |
|---|---|
| ArgumentOutOfRangeException | indexA, indexB, or length is negative. -or- The sum of indexA and length is greater than strA.Length. -or- The sum of indexB and length is greater than strB.Length. |
indexA, indexB, and length must be positive.
The number of characters compared is the lesser of the length of strA less indexA, the length of strB less indexB, and length.
value
| Value | Condition |
|---|---|
| Less than zero | This instance is less than . |
| Zero | This instance is equal to . |
| Greater than zero | This instance is greater than value. -or- value is null. |
| Exception Type | Condition |
|---|---|
| ArgumentException | value is not a String. |
By definition, any String, including the empty string, compares greater than null; and two null references compare equal to each other.
This method performs a case-sensitive operation. The method uses the current culture to determine the ordering of individual characters. Uppercase letters evaluate greater than their lowercase equivalents. The two strings are compared on a character-by-character basis.
strB
| Value | Condition |
|---|---|
| Less than zero | This instance is less than . |
| Zero | This instance is equal to . |
| Greater than zero | This instance is greater than value. -or- value is null. |
arg0
args
| Exception Type | Condition |
|---|---|
| ArgumentNullException | args is null. |
values
| Exception Type | Condition |
|---|---|
| ArgumentNullException | values is null. |
arg0
arg1
If either of the arguments is an array reference, the method concatenates a string representing that array, instead of its members (for example, "System.String[]").
str0
str1
arg0
arg1
arg2
str0
str1
str2
arg0
arg1
arg2
arg3
An String.Empty string is used in place of any null argument.
str0
str1
str2
str3
str
| Exception Type | Condition |
|---|---|
| ArgumentNullException | str is null. |
public void CopyTo( |
sourceIndex
destination
destinationIndex
count
| Exception Type | Condition |
|---|---|
| ArgumentNullException | destination is null. |
| ArgumentOutOfRangeException | sourceIndex, destinationIndex, or count is negative -or- count is greater than the length of the substring from startIndex to the end of this instance -or- count is greater than the length of the subarray from destinationIndex to the end of destination |
sourceIndex and destinationIndex are zero-based.
value