[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
Exception Type | Condition |
---|---|
ArgumentNullException | value is null. |
The comparison is case-sensitive.
obj
Exception Type | Condition |
---|---|
NullReferenceException | This instance is null. |
This comparison is case-sensitive.
value
Exception Type | Condition |
---|---|
NullReferenceException | This instance is null. |
a
b
~String(); |
format
arg0
Exception Type | Condition |
---|---|
ArgumentNullException | format or arg0 is null. |
FormatException | The format specification in format is invalid. -or- The number indicating an argument to be formatted (N) is less than zero, or larger than or equal to the length of the args array. |
If argN implements IFormattable, then argN.Format(formatString, null) provides formatting; otherwise argN.ToString() provides formatting. If argN is null, then an empty string is used in its place.
If formatString is omitted, the ToString() method of the argument specified by N provides formatting.If the value of format is, "Thank you for your purchase of {0:####} copies of Microsoft® .NET (Core Reference).", and arg0 is an Int16 with the value 123, then the return value will be:
"Thank you for your purchase of 123 copies of Microsoft® .NET (Core Reference)."
If the value of format is, "Brad's dog has {0,-8:G} fleas.", arg0 is an Int16 with the value 42, (and in this example, underscores represent padding spaces) then the return value will be:
"Brad's dog has 42______ fleas."
format
args
Exception Type | Condition |
---|---|
ArgumentNullException | format or args is null. |
FormatException | format is invalid. -or- The number indicating an argument to be formatted (N) is less than zero, or larger than or equal to the length of the args array. |
If argN implements IFormattable, then argN.Format(formatString, null) provides formatting; otherwise argN.ToString() provides formatting. If argN is null, then an empty string is used in its place.
If formatString is omitted, the ToString() method of the argument specified by N provides formatting.If the value of format is, "Thank you for your purchase of {0:####} copies of Microsoft® .NET (Core Reference).", and arg[0] is an Int16 with the value 123, then the return value will be:
"Thank you for your purchase of 123 copies of Microsoft® .NET (Core Reference)."
If the value of format is, "Brad's dog has {0,-8:G} fleas.", arg[0] is an Int16 with the value 42, (and in this example, underscores represent padding spaces) then the return value will be:
"Brad's dog has 42______ fleas."
public static string Format(I Format( |
provider
format
args
Exception Type | Condition |
---|---|
ArgumentNullException | format or args is null. |
FormatException | format is invalid. -or- The number indicating an argument to be formatted (N) is less than zero, or larger than or equal to the length of the args array. |
If argN implements IFormattable, then argN.Format(formatString, null) provides formatting; otherwise argN.ToString() provides formatting. If argN is null, then an empty string is used in its place.
If formatString is omitted, the ToString() method of the argument specified by N provides formatting.If the value of format is, "Thank you for your purchase of {0:####} copies of Microsoft® .NET (Core Reference).", and arg[0] is an Int16 with the value 123, then the return value will be:
"Thank you for your purchase of 123 copies of Microsoft® .NET (Core Reference)."
If the value of format is, "Brad's dog has {0,-8:G} fleas.", arg[0] is an Int16 with the value 42, (and in this example, underscores represent padding spaces) then the return value will be:
"Brad's dog has 42______ fleas."
format
arg0
arg1
Exception Type | Condition |
---|---|
ArgumentNullException | format is null. |
FormatException | format is invalid. -or- The number indicating an argument to be formatted is less than zero, or larger than or equal to the number of provided objects to be formatted. |
If argN implements IFormattable, then argN.Format(formatString, null) provides formatting; otherwise argN.ToString() provides formatting. If argN is null, then an empty string is used in its place.
If formatString is omitted, the ToString() method of the argument specified by N provides formatting.
If the value of format is, "Thank you for your purchase of {0:####} copies of Microsoft® .NET (Core Reference).", and arg0 is an Int16 with the value 123, then the return value will be:
"Thank you for your purchase of 123 copies of Better Basket Weaving."
If the value of format is, "Brad's dog has {0,-8:G} fleas.", arg0 is an Int16 with the value 42, (and in this example, underscores represent padding spaces) then the return value will be:
"Brad's dog has 42______ fleas."
format
arg0
arg1
arg2
Exception Type | Condition |
---|---|
ArgumentNullException | format is null. |
FormatException | format is invalid. -or- The number indicating an argument to be formatted is less than zero, or larger than or equal to the number of provided objects to be formatted. |
If argN implements IFormattable, then argN.Format(formatString, null) provides formatting; otherwise argN.ToString() provides formatting. If argN is null, then an empty string is used in its place.
If formatString is omitted, the ToString() method of the argument specified by N provides formatting.If the value of format is, "Thank you for your purchase of {0:####} copies of Microsoft® .NET (Core Reference).", and arg0 is an Int16 with the value 123, then the return value will be:
"Thank you for your purchase of 123 copies of Microsoft® .NET (Core Reference)."
If the value of format is, "Brad's dog has {0,-8:G} fleas.", arg0 is an Int16 with the value 42, (and in this example, underscores represent padding spaces) then the return value will be:
"Brad's dog has 42______ fleas."
public CharEnumerator GetEnumerator(); |
public override int GetHashCode(); |
public Type GetType(); |
public TypeCode GetTypeCode(); |
value
The search for value is case-sensitive.
This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if the Unicode values are the same. To perform a culture-sensitive search, use the CompareInfo.IndexOf method, where a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture.
value
Value | Meaning |
---|---|
A positive index position. | was found. |
0 | is String.Empty . |
-1 | was not found. |
Exception Type | Condition |
---|---|
ArgumentNullException | value is null. |
value
startIndex
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | startIndex is less than zero or specifies a position beyond the end of this instance. |
The search ranges from startIndex to the end of the string.
The search for value is case-sensitive.
This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if the Unicode values are the same. To perform a culture-sensitive search, use the CompareInfo.IndexOf method, where a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture.
value
startIndex
Value | Meaning |
---|---|
A positive index position. | was found. |
is String.Empty . | |
-1 | was not found. |
Exception Type | Condition |
---|---|
ArgumentNullException | anyOf is null. |
ArgumentOutOfRangeException | startIndex is negative. -or- startIndex specifies a position not within this instance. |
value
startIndex
count
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | count or startIndex is negative. -or- count + startIndex specifies a position beyond the end of this instance. |
Index numbering starts from zero.
The search for value is case-sensitive.
This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if the Unicode values are the same. To perform a culture-sensitive search, use the CompareInfo.IndexOf method, where a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture.
value
startIndex
count
Value | Meaning |
---|---|
A positive index position. | was found. |
is String.Empty . | |
-1 | was not found. |
Exception Type | Condition |
---|---|
ArgumentNullException | value is null. |
ArgumentOutOfRangeException | count or startIndex is negative. -or- count plus startIndex specify a position not within this instance. |
The search is case-sensitive and uses the current culture.
anyOf
Exception Type | Condition |
---|---|
ArgumentNullException | anyOf is null. |
The search for anyOf is case-sensitive.
This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if the Unicode values are the same. To perform a culture-sensitive search, use the CompareInfo.IndexOf method, where a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture.
anyOf
startIndex
Exception Type | Condition |
---|---|
ArgumentNullException | anyOf is null. |
ArgumentOutOfRangeException | startIndex is negative. -or- startIndex is greater than the number of characters in this instance. |
The search ranges from startIndex to the end of the string.
The search for anyOf is case-sensitive.
This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if the Unicode values are the same. To perform a culture-sensitive search, use the CompareInfo.IndexOf method, where a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture.
anyOf
startIndex
count
Exception Type | Condition |
---|---|
ArgumentNullException | anyOf is null. |
ArgumentOutOfRangeException | count or startIndex is negative. -or- count + startIndex is greater than the number of characters in this instance. |
Index numbering starts from zero.
The search for anyOf is case-sensitive.
This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if the Unicode values are the same. To perform a culture-sensitive search, use the CompareInfo.IndexOf method, where a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture.
startIndex
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null. |
ArgumentOutOfRangeException | startIndex is negative or greater than the length of this instance. |
For example, the return value of
"abc".Insert(2, "XYZ")
is "abXYZc".
str
Exception Type | Condition |
---|---|
ArgumentNullException | str is null. |
The intern pool conserves string storage. If you assign a literal string constant to several variables, each variable is set to reference the same constant in the intern pool instead of referencing several different instances of String that have identical values.
This method looks up str in the intern pool. If str exists, a reference to it is returned. If str does not exist, an instance equal to str is added to the intern pool and a reference that instance is returned.
The code below generates a new String, "MyTest", using the StringBuilder class, and puts it into the intern pool. The string, s1, has already been interned because it is a literal in our program. The string, s2, has the same value, but is a different object than the one referenced by s3.
String s1 =
"MyTest";
String s2 =
new StringBuilder().Append("My").Append("Test").ToString();
String s3 =
String.Intern(s2);
Console.WriteLine((Object)s2==(Object)s1); // Different
references.
Console.WriteLine((Object)s3==(Object)s2); // The same reference.
Compare this method to the String.IsInterned method.
str
Exception Type | Condition |
---|---|
ArgumentNullException | str is null. |
The intern pool conserves string storage. If you assign a literal string constant to several variables, each variable is set to reference the same constant in the intern pool instead of referencing several different instances of String that have identical values.
This method looks up str in the intern pool. If str has already been interned, a reference to that instance is returned; otherwise, null is returned.
Compare this method to the String.Intern method.
This method does not return a Boolean value, but can still be used where a Boolean is needed.
separator
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null. |
Join(separator, value)
returns "apple, orange, grape, pear".separator
value
startIndex
count
-or-
String.Empty if count is zero, value has no elements, or separator and all the elements of value are String.Empty.
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | startIndex plus count is greater than the number of elements in value. |
Join(separator, value, 1, 2)
returns "orange, grape".value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null. |
value
Value | Meaning |
---|---|
A positive index position. | was found. |
0 | is String.Empty . |
-1 | was not found. |
Exception Type | Condition |
---|---|
ArgumentNullException | value is null. |
value
startIndex
Exception Type | Condition |
---|---|
ArgumentNullException | value is null. |
ArgumentOutOfRangeException | startIndex is less than zero or greater than the length of this instance. |
value
startIndex
Value | Meaning |
---|---|
A positive index position. | was found. |
is String.Empty . | |
-1 | was not found. |
Exception Type | Condition |
---|---|
ArgumentNullException | value is null. |
ArgumentOutOfRangeException | startIndex is less than zero or specifies a position not within this instance. |
value
startIndex
count
Exception Type | Condition |
---|---|
ArgumentNullException | value is null. |
ArgumentOutOfRangeException | startIndex or count is less than zero or greater than the length of this instance. |
value
startIndex
count
Value | Meaning |
---|---|
A positive index position. | was found. |
is String.Empty . | |
-1 | was not found. |
Exception Type | Condition |
---|---|
ArgumentNullException | value is null. |
ArgumentOutOfRangeException | count or startIndex is negative. -or- count plus startIndex specify a position not within this instance. |
anyOf
Exception Type | Condition |
---|---|
ArgumentNullException | anyOf is null. |
This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if the Unicode values are the same. To perform a culture-sensitive search, use the CompareInfo.IndexOf method, where a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture.
anyOf
startIndex
Exception Type | Condition |
---|---|
ArgumentNullException | anyOf is null. |
ArgumentOutOfRangeException | startIndex specifies a position not within this instance. |
This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if the Unicode values are the same. To perform a culture-sensitive search, use the CompareInfo.IndexOf method, where a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture.
anyOf
startIndex
count
Exception Type | Condition |
---|---|
ArgumentNullException | anyOf is null. |
ArgumentOutOfRangeException | count or startIndex is negative. -or- count plus startIndex specify a position not within this instance. |
This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if the Unicode values are the same. To perform a culture-sensitive search, use the CompareInfo.IndexOf method, where a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture.
protected object MemberwiseClone(); |
a
b
a
b
totalWidth
-or-
If totalWidth is less than the length of this instance, a new String that is identical to this instance.Exception Type | Condition |
---|---|
ArgumentException | totalWidth is less than zero. |
totalWidth
paddingChar
-or-
If totalWidth is less than the length of this instance, a new String that is identical to this instance.Exception Type | Condition |
---|---|
ArgumentException | totalWidth is less than zero. |
totalWidth
-or-
If totalWidth is less than the length of this instance, a new String that is identical to this instance.
Exception Type | Condition |
---|---|
ArgumentException | totalWidth is less than zero. |
totalWidth
paddingChar
-or-
If totalWidth is less than the length of this instance, a new String that is identical to this instance.
Exception Type | Condition |
---|---|
ArgumentException | totalWidth is less than zero. |
startIndex
count
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | Either startIndex or count is less than zero. -or- startIndex plus count is greater than the length of this instance. |
String s
= "123abc456";
Console.WriteLine(s.Remove(3, 3));
oldChar
newChar
oldValue
newValue
separator
-or-
An array of substrings if this instance is delimited by one or more of the characters in separator.
-or-
An array of the substrings in this instance delimited by white space characters if those characters occur and separator is null or contains no delimiter characters.
String.Empty is returned for any substring where two delimiters are adjacent, or a delimiter is found at the beginning or end of this instance.
Delimiter characters are not included in the substrings.
Input | separator | Output |
---|---|---|
"42, 12, 19" | new Char[] {',', ' '} | {"42", "", "12", "", "19"} |
"42..12..19" | new Char[] {'.'} | {"42", "", "12", "", "19"} |
"Banana" | new Char[] {'.'} | {"Banana"} |
"Darb\nSmarba" | new Char[] {} | {"Darb", "Smarba"} |
"Darb\nSmarba" | null | {"Darb", "Smarba"} |
separator
count
-or-
An array of substrings if this instance is delimited by one or more of the characters in separator.
-or-
An array of the substrings in this instance delimited by white space characters if those characters occur and separator is null or contains no delimiter characters.
String.Empty is returned for any substring where two delimiters are adjacent, or a delimiter is found at the beginning or end of this instance.
Delimiter characters are not included in the substrings.
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | count is negative. |
For example:
Input | separator, count | Output |
---|---|---|
"42, 12, 19" | new Char[] {',', ' '}, 2 | {"42", " 12, 19"} |
"42..12..19" | new Char[] {'.'},4 | {"42", "", "12", ".19"} |
"Banana" | new Char[] {'.'},2 | {"Banana"} |
"Darb\nSmarba" | new Char[] {}, 1 | {"Darb\nSmarba"} |
"Darb\nSmarba" | new Char[] null,2 | {"Darb", "Smarba"} |
"Darb\nSmarba" | new Char[] null,100 | {"Darb", "Smarba"} |
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null. |
startIndex
-or-
String.Empty if startIndex is equal to the length of this instance.
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | startIndex is less than zero or greater than the length of this instance. |
startIndex
length
-or-
String.Empty if startIndex is equal to the length of this instance and length is zero.
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | startIndex plus length indicates a position not within this instance. -or- startIndex or length is less than zero. |
String myString = "abc"; bool test1 = String.Compare(myString.Substring(2, 1), "c") == 0; // This is true. myString.Substring(3, 1); // This throws ArgumentOutOfRangeException. bool test2 = String.Compare(myString.Substring(3, 0), String.Empty) == 0; // This is true.
public char[] ToCharArray(); |
startIndex
length
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | startIndex or length is less than zero. -or- startIndex plus length is greater than the length of this instance. |
public string ToLower(); |
public string ToLower( |
culture
Exception Type | Condition |
---|---|
ArgumentNullException | culture is null. |
public override string ToString(); |
public string ToString( |
provider
public string ToUpper(); |
public string ToUpper( |
culture
Exception Type | Condition |
---|---|
ArgumentNullException | culture is null. |
public string Trim(); |
trimChars
trimChars
trimChars