System.String Class

Assembly: Mscorlib.dll
Namespace: System
Summary
Represents an immutable series of characters.
C# Syntax:
[Serializable]
public sealed class String : IComparable, ICloneable, IConvertible, IEnumerable
Thread Safety
This type is safe for multithreaded operations.
Remarks
An instance of String is said to be immutable because its value cannot be modified once it has been created. Methods that appear to modify a String actually return a new String containing the modification. Use the StringBuilder class if it is necessary to actually modify the contents of a string-like object.

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.

Example
The following examples are for illustrative purposes only; they will not run as specified in the comments. The first set of examples shows the use of relational operators.
See also:
System Namespace | IComparable | ICloneable | IConvertible | IEnumerable | StringBuilder | CultureInfo | MSDN: formattingoverview

System.String Member List:

Public Constructors
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.
Public Fields
Empty Represents the empty string. This field is read-only.
Public Properties
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.
Public Methods
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.
Public Operators and Type Conversions
op_Equality Determines whether two specified String objects have the same value.
op_Inequality Determines whether two specified String objects have different values.
Protected Methods
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:


System.String Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the String class to the value indicated by a specified pointer to an array of Unicode characters.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
unsafe public String(
   char* value
);
Parameters:

value

A pointer to a null terminated array of Unicode characters.

Remarks
If value is a null pointer, an String.Empty instance is initialized.

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.

See also:
Char

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the String class to the value indicated by an array of Unicode characters.
C# Syntax:
public String(
   char[] value
);
Parameters:

value

An array of Unicode characters.

Remarks
If value is null or contains no element, an String.Empty instance is initialized.
See also:
Char

Return to top


Overloaded ctor #3
Summary
Initializes a new instance of the String class to the value indicated by a pointer to an array of 8-bit signed integers.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
unsafe public String(
   sbyte* value
);
Parameters:

value

A pointer to a null terminated array of 8-bit signed integers.

Remarks
If value is a null pointer, an String.Empty instance is initialized.

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.

See also:
SByte

Return to top


Overloaded ctor #4
Summary
Initializes a new instance of the String class to the value indicated by a specified Unicode character repeated a specified number of times.
C# Syntax:
public String(
   char c,
   int count
);
Parameters:

c

A Unicode character.

count

The number of times c occurs.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException count is less than zero.
Remarks
If count is zero, an String.Empty instance is initialized.
See also:
Char | Int32

Return to top


Overloaded ctor #5
Summary
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.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
unsafe public String(
   char* value,
   int startIndex,
   int length
);
Parameters:

value

A pointer to an array of Unicode characters.

startIndex

The starting position within value.

length

The number of characters within value to use.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException startIndex or length is less than zero.

-or-

value is a null pointer and length is not zero.

Remarks
If length is zero, an String.Empty instance is initialized.

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.

See also:
Char | Int32

Return to top


Overloaded ctor #6
Summary
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.
C# Syntax:
public String(
   char[] value,
   int startIndex,
   int length
);
Parameters:

value

An array of Unicode characters.

startIndex

The starting position within value.

length

The number of characters within value to use.

Exceptions
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.

Remarks
If length is zero, an String.Empty instance is initialized.

This constructor copies Unicode characters from value, starting at startIndex and ending at (startIndex + length - 1).

See also:
Char | Int32

Return to top


Overloaded ctor #7
Summary
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.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
unsafe public String(
   sbyte* value,
   int startIndex,
   int length
);
Parameters:

value

A pointer to an array of 8-bit signed integers.

startIndex

The starting position within value.

length

The number of characters within value to use.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException startIndex or length is less than zero.

-or-

value is a null pointer and length is not zero.

Remarks
If length is zero, an String.Empty instance is initialized.

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.

See also:
SByte | Int32

Return to top


Overloaded ctor #8
Summary
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.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
unsafe public String(
   sbyte* value,
   int startIndex,
   int length,
   Encoding enc
);
Parameters:

value

A pointer to an array of 8-bit signed integers.

startIndex

The starting position within value.

length

The number of characters within value to use.

enc

An Encoding object that specifies how the array referenced by value is encoded.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException startIndex or length is less than zero.
Remarks
If value is a null pointer, an String.Empty instance is initialized.
See also:
SByte | Int32

Return to top


Field: Empty
Summary
Represents the empty string. This field is read-only.
C# Syntax:
public static readonly string Empty;
Remarks
The value of this field is the zero-length string, "".

Return to top


Property: Chars (read-only)
Summary
Gets the character at a specified character position in this instance.
C# Syntax:
No member name public char this[int index] {get;}
Parameters:

index

A character position in this instance.

Exceptions
Exception Type Condition
IndexOutOfRangeException index is greater than or equal to the length of this object or less than zero.
Remarks
index is zero-based.
See also:
Char | String.GetEnumerator | Int32

Return to top


Property: Length (read-only)
Summary
Gets the number of characters in this instance.
C# Syntax:
public int Length {get;}
See also:
Int32

Return to top


Method: Clone()
Summary
Returns a reference to this instance of String.
C# Syntax:
public object Clone();
Return Value:
This instance of String.
Implements:
ICloneable.Clone
Remarks
The return value is not an independent copy of this instance; it is simply another view of the same data. Use the String.Copy or String.CopyTo method to create a separate String object with the same value as this instance.
See also:
Object | String.Copy | String.CopyTo

Return to top


Overloaded Method: Compare(
   string strA,
   string strB
)
Summary
Compares two specified String objects.
C# Syntax:
public static int Compare(
   string strA,
   string strB
);
Parameters:

strA

The first String.

strB

The second String.

Return Value:
A 32-bit signed integer indicating the lexical relationship between the two comparands.

Value Meaning
Less than zero is less than .
Zero equals .
Greater than zero is greater than .
Remarks
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.

See also:
Int32 | String.CompareOrdinal | String.CompareTo

Return to top


Overloaded Method: Compare(
   string strA,
   string strB,
   bool ignoreCase
)
Summary
Compares two specified String objects, ignoring or honoring their case.
C# Syntax:
public static int Compare(
   string strA,
   string strB,
   bool ignoreCase
);
Parameters:

strA

The first String.

strB

The second String.

ignoreCase

A Boolean indicating a case-sensitive or insensitive comparison. (true indicates a case-insensitive comparison.)

Return Value:
A 32-bit signed integer indicating the lexical relationship between the two comparands.

Value Meaning
Less than zero is less than .
Zero equals .
Greater than zero is greater than .
Remarks
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.

See also:
Int32 | String.CompareOrdinal | String.CompareTo | CompareInfo.IsPrefix

Return to top


Overloaded Method: Compare(
   string strA,
   string strB,
   bool ignoreCase,
   CultureInfo culture
)
Summary
Compares two specified String objects, ignoring or honoring their case, and honoring culture-specific information about their formatting.
C# Syntax:
public static int Compare(
   string strA,
   string strB,
   bool ignoreCase,
   CultureInfo culture
);
Parameters:

strA

The first String.

strB

The second String.

ignoreCase

A Boolean indicating a case-sensitive or insensitive comparison. (true indicates a case-insensitive comparison.)

culture

A CultureInfo object that supplies culture-specific formatting information.

Return Value:
A 32-bit signed integer indicating the lexical relationship between the two comparands.

Value Meaning
Less than zero is less than .
Zero equals .
Greater than zero is greater than .
Exceptions
Exception Type Condition
ArgumentNullException culture is null.
Remarks
culture specifies a CultureInfo object, which provides culture-specific information that can affect the comparison.

By definition, any String, including the empty string, compares greater than a null reference; and two null references compare equal to each other.

See also:
Int32 | String.CompareOrdinal | String.CompareTo | CompareInfo.IsPrefix | Boolean

Return to top


Overloaded Method: Compare(
   string strA,
   int indexA,
   string strB,
   int indexB,
   int length
)
Summary
Compares substrings of two specified String objects.
C# Syntax:
public static int Compare(
   string strA,
   int indexA,
   string strB,
   int indexB,
   int length
);
Parameters:

strA

The first String.

indexA

The position of the substring within strA.

strB

The second String.

indexB

The position of the substring within strB.

length

The maximum number of characters in the substrings to compare.

Return Value:
A 32-bit signed integer indicating the lexical relationship between the two comparands.

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 .
Exceptions
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.

Remarks
indexA and indexB are zero-based.

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.

See also:
Int32 | String.CompareOrdinal | String.CompareTo

Return to top


Overloaded Method: Compare(
   string strA,
   int indexA,
   string strB,
   int indexB,
   int length,
   bool ignoreCase
)
Summary
Compares substrings of two specified String objects, ignoring or honoring their case.
C# Syntax:
public static int Compare(
   string strA,
   int indexA,
   string strB,
   int indexB,
   int length,
   bool ignoreCase
);
Parameters:

strA

The first String.

indexA

The position of the substring within strA.

strB

The second String.

indexB

The position of the substring within strB.

length

The maximum number of characters in the substrings to compare.

ignoreCase

A Boolean indicating a case-sensitive or insensitive comparison. (true indicates a case-insensitive comparison.)

Return Value:
A 32-bit signed integer indicating the lexical relationship between the two comparands.

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 .
Exceptions
Exception Type Condition
ArgumentOutOfRangeException Either index is outside the series of characters to be compared.

-or-

length is negative.

Remarks
indexA and indexB are zero-based.length cannot be 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.

See also:
Int32 | String.CompareOrdinal | String.CompareTo

Return to top


Overloaded Method: Compare(
   string strA,
   int indexA,
   string strB,
   int indexB,
   int length,
   bool ignoreCase,
   CultureInfo culture
)
Summary
Compares substrings of two specified String objects, ignoring or honoring their case, and honoring culture-specific information about their formatting.
C# Syntax:
public static int Compare(
   string strA,
   int indexA,
   string strB,
   int indexB,
   int length,
   bool ignoreCase,
   CultureInfo culture
);
Parameters:

strA

The first String.

indexA

The position of the substring within strA.

strB

The second String.

indexB

The position of the substring within the strB.

length

The maximum number of characters in the substrings to compare.

ignoreCase

A Boolean indicating a case-sensitive or insensitive comparison. (true indicates a case-insensitive comparison.)

culture

A CultureInfo object that supplies culture-specific formatting information.

Return Value:
An integer indicating the lexical relationship between the two comparands.

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 .
Exceptions
Exception Type Condition
ArgumentNullException culture is null.
ArgumentOutOfRangeException Either index is outside the series of characters to be compared.

-or-

length is negative.

Remarks
culture specifies a CultureInfo object, which provides culture-specific information that can affect the comparison.length cannot be 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.

See also:
Int32 | String.CompareOrdinal | String.CompareTo

Return to top


Overloaded Method: CompareOrdinal(
   string strA,
   string strB
)
Summary
Compares two specified String objects, without considering the local national language or culture.
C# Syntax:
public static int CompareOrdinal(
   string strA,
   string strB
);
Parameters:

strA

The first String.

strB

The second String.

Return Value:
An integer indicating the lexical relationship between the two comparands.

Permission Description
Less than zero is less than .
Zero and are equal.
Greater than zero is greater than .
Remarks
By definition, any String, including the empty string, compares greater than null; and two null references compare equal to each other.
See also:
Int32 | String.Compare | String.CompareTo

Return to top


Overloaded Method: CompareOrdinal(
   string strA,
   int indexA,
   string strB,
   int indexB,
   int length
)
Summary
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.
C# Syntax:
public static int CompareOrdinal(
   string strA,
   int indexA,
   string strB,
   int indexB,
   int length
);
Parameters:

strA

The first String.

indexA

The starting index of the substring in strA.

strB

The second String.

indexB

The starting index of the substring in strB.

length

The maximum number of characters in the substrings to compare.

Return Value:
A 32-bit signed integer indicating the lexical relationship between the two comparands.

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 .
Exceptions
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.

Remarks
By definition, any String, including the empty string, compares greater than null; and two null references compare equal to each other.

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.

See also:
String.Compare | String.CompareTo | Int32

Return to top


Overloaded Method: CompareTo(
   object value
)
Summary
Compares this instance with a specified Object.
C# Syntax:
public int CompareTo(
   object value
);
Parameters:

value

An Object that evaluates to a String.

Return Value:
A 32-bit signed integer indicating the lexical relationship between the two comparands.

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.
Exceptions
Exception Type Condition
ArgumentException value is not a String.
Implements:
IComparable.CompareTo
Remarks
value must be a String object.

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.

See also:
String.Compare | String.CompareOrdinal

Return to top


Overloaded Method: CompareTo(
   string strB
)
Summary
Compares this instance with a specified String object.
C# Syntax:
public int CompareTo(
   string strB
);
Parameters:

strB

A String.

Return Value:
A 32-bit signed integer indicating the lexical relationship between the two comparands.

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.
Remarks
By definition, any String, including the empty string, compares greater than a null reference; and two null references compare equal to each other.
See also:
String.Compare | String.CompareOrdinal

Return to top


Overloaded Method: Concat(
   object arg0
)
Summary
Creates the String representation of a specified object.
C# Syntax:
public static string Concat(
   object arg0
);
Parameters:

arg0

An Object or null.

Return Value:
The String representation of the value of arg0.
Remarks
An String.Empty string is used in place of any null argument.
See also:
Object | String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Substring | String.Trim

Return to top


Overloaded Method: Concat(
   params object[] args
)
Summary
Concatenates the String representations of the elements in a specified Object array.
C# Syntax:
public static string Concat(
   params object[] args
);
Parameters:

args

An Object array.

Return Value:
The concatenated String representations of the values of the elements in args.
Exceptions
Exception Type Condition
ArgumentNullException args is null.
Remarks
An String.Empty string is used in place of any null object in the array.
See also:
Object | String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Substring | String.Trim

Return to top


Overloaded Method: Concat(
   params string[] values
)
Summary
Concatenates the elements of a specified String array.
C# Syntax:
public static string Concat(
   params string[] values
);
Parameters:

values

An array of String instances.

Return Value:
The concatenated elements of values.
Exceptions
Exception Type Condition
ArgumentNullException values is null.
Remarks
An String.Empty string is used in place of any null object in the array.
See also:
String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Substring | String.Trim

Return to top


Overloaded Method: Concat(
   object arg0,
   object arg1
)
Summary
Concatenates the String representations of two specified objects.
C# Syntax:
public static string Concat(
   object arg0,
   object arg1
);
Parameters:

arg0

The first Object.

arg1

The second Object.

Return Value:
The concatenated String representations of the values of arg0 and arg1.
Remarks
An String.Empty string is used in place of any null argument.

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[]").

See also:
Object | String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Substring | String.Trim

Return to top


Overloaded Method: Concat(
   string str0,
   string str1
)
Summary
Concatenates two specified instances of String.
C# Syntax:
public static string Concat(
   string str0,
   string str1
);
Parameters:

str0

The first String.

str1

The second String.

Return Value:
The concatenation of str0 and str1.
Remarks
An String.Empty string is used in place of any null argument.
See also:
String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Substring | String.Trim

Return to top


Overloaded Method: Concat(
   object arg0,
   object arg1,
   object arg2
)
Summary
Concatenates the String representations of three specified objects.
C# Syntax:
public static string Concat(
   object arg0,
   object arg1,
   object arg2
);
Parameters:

arg0

The first Object.

arg1

The second Object.

arg2

The third Object.

Return Value:
The concatenated String representations of the values of arg0, arg1, and arg2.
Remarks
An String.Empty string is used in place of any null argument.
See also:
Object | String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Substring | String.Trim

Return to top


Overloaded Method: Concat(
   string str0,
   string str1,
   string str2
)
Summary
Concatenates three specified instances of String.
C# Syntax:
public static string Concat(
   string str0,
   string str1,
   string str2
);
Parameters:

str0

The first String.

str1

The second String.

str2

The third String.

Return Value:
The concatenation of str0, str1, and str2.
Remarks
An String.Empty string is used in place of any null argument.
See also:
String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Substring | String.Trim

Return to top


Overloaded Method: Concat
Summary
Concatenates the String representations of three specified objects and a variable-length parameter list.
Parameters:

arg0

The first Object.

arg1

The second Object.

arg2

The third Object.

arg3

The fourth Object.

Return Value:
The concatenated String representations of the values of arg0, arg1, arg2, arg3, and zero or more objects specified in a variable-length parameter list.
Remarks
Additional arguments can be included in a variable-length parameter list.

An String.Empty string is used in place of any null argument.

See also:
Object | ArgIterator | String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Substring | String.Trim

Return to top


Overloaded Method: Concat(
   string str0,
   string str1,
   string str2,
   string str3
)
Summary
Concatenates four specified instances of String.
C# Syntax:
public static string Concat(
   string str0,
   string str1,
   string str2,
   string str3
);
Parameters:

str0

The first String.

str1

The second String.

str2

The third String.

str3

The fourth String.

Return Value:
The concatenation of str0, str1, str2, and str3.
Remarks
An String.Empty string is used in place of any null object in the array.
See also:
String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Substring | String.Trim

Return to top


Method: Copy(
   string str
)
Summary
Creates a new instance of String with the same value as a specified String.
C# Syntax:
public static string Copy(
   string str
);
Parameters:

str

The String to copy.

Return Value:
A new String with the same value as str.
Exceptions
Exception Type Condition
ArgumentNullException str is null.
See also:
String.Empty | DBNull

Return to top


Method: CopyTo(
   int sourceIndex,
   char[] destination,
   int destinationIndex,
   int count
)
Summary
Copies a specified number of characters from a specified position in this instance to a specified position in an array of Unicode characters.
C# Syntax:
public void CopyTo(
   int sourceIndex,
   char[] destination,
   int destinationIndex,
   int count
);
Parameters:

sourceIndex

A character position in this instance.

destination

An array of Unicode characters.

destinationIndex

An array element in destination.

count

The number of characters in this instance to copy to destination.

Exceptions
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

Remarks
count characters are copied from the sourceIndex position of this instance to the destinationIndex position of destination.

sourceIndex and destinationIndex are zero-based.

See also:
Char | Int32 | String.Insert | String.Substring

Return to top


Method: EndsWith(
   string value
)
Summary
Determines whether the end of this instance matches the specified String.
C# Syntax:
public bool EndsWith(
   string value
);
Parameters:

value

A String.

Return Value:
true if the end of this instance matches value; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException value is null.
Remarks
This method compares value with the substring at the end of the current instance that has a length of value.Length.

The comparison is case-sensitive.

See also:
String.StartsWith

Return to top


Overloaded Method: Equals(
   object obj
)
Summary
Determines whether this instance of String and a specified object, which must be a String, have the same value.
C# Syntax:
public override bool Equals(
   object obj
);
Parameters:

obj

An Object.

Return Value:
true if obj is a String and its value is the same as this instance; otherwise, false.
Exceptions
Exception Type Condition
NullReferenceException This instance is null.
Remarks
This method checks for value equality.

This comparison is case-sensitive.

See also:
Object | String.Compare | String.CompareOrdinal | String.CompareTo

Return to top


Overloaded Method: Equals(
   string value
)
Summary
Determines whether this instance and a specified String have the same value.
C# Syntax:
public bool Equals(
   string value
);
Parameters:

value

A String.

Return Value:
true if the value of value is the same as this instance; otherwise, false.
Exceptions
Exception Type Condition
NullReferenceException This instance is null.
Remarks
This comparison is case-sensitive.
See also:
Object | String.Compare | String.CompareOrdinal | String.CompareTo

Return to top


Overloaded Method: Equals(
   string a,
   string b
)
Summary
Determines whether two specified String objects have the same value.
C# Syntax:
public static bool Equals(
   string a,
   string b
);
Parameters:

a

A String or null.

b

A String or null.

Return Value:
true if the value of a is the same as the value of b; otherwise, false.
Remarks
The comparison is case-sensitive.
See also:
Object | String.Compare | String.CompareOrdinal | String.CompareTo

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~String();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: Format(
   string format,
   object arg0
)
Summary
Replaces the format specification in a specified String with the textual equivalent of the value of a specified Object instance.
C# Syntax:
public static string Format(
   string format,
   object arg0
);
Parameters:

format

A String containing zero or more format specifications.

arg0

An Object to be formatted.

Return Value:
A copy of format in which the first format specification has been replaced by the String equivalent of arg0.
Exceptions
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.

Remarks
The format parameter is embedded with zero or more format specifications of the form, { N [, M ][: formatString ]}, where:

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."

See also:
Object | IFormattable | MSDN: formattingoverview

Return to top


Overloaded Method: Format(
   string format,
   params object[] args
)
Summary
Replaces the format specification in a specified String with the textual equivalent of the value of a corresponding Object instance in a specified array.
C# Syntax:
public static string Format(
   string format,
   params object[] args
);
Parameters:

format

A String containing zero or more format specifications.

args

An Object array containing zero or more objects to be formatted.

Return Value:
A copy of format in which the format specifications have been replaced by the String equivalent of the corresponding instances of Object in args.
Exceptions
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.

Remarks
The format parameter is embedded with zero or more format specifications of the form, { N [, M ][: formatString ]}, where:

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."

See also:
Object | IFormattable | MSDN: formattingoverview

Return to top


Overloaded Method: Format(
   IFormatProvider provider,
   string format,
   params object[] args
)
Summary
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.
C# Syntax:
public static string Format(I Format(
   IFormatProvider provider,
   string format,
   params object[] args
);
Parameters:

provider

An IFormatProvider that supplies culture-specific formatting information.

format

A String containing zero or more format specifications.

args

An Object array containing zero or more objects to be formatted.

Return Value:
A copy of format in which the format specifications have been replaced by the String equivalent of the corresponding instances of Object in args.
Exceptions
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.

Remarks
The format parameter is embedded with zero or more format specifications of the form, { N [, M ][: formatString ]}, where:

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."

See also:
Object | IFormattable | IFormatProvider | MSDN: formattingoverview

Return to top


Overloaded Method: Format(
   string format,
   object arg0,
   object arg1
)
Summary
Replaces the format specification in a specified String with the textual equivalent of the value of two specified Object instances.
C# Syntax:
public static string Format(
   string format,
   object arg0,
   object arg1
);
Parameters:

format

A String containing zero or more format specifications.

arg0

The first Object to be formatted.

arg1

The second Object to be formatted.

Return Value:
A copy of format in which the first and second format specifications have been replaced by the String equivalent of the arg0 and arg1.
Exceptions
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.

Remarks
The format parameter is embedded with zero or more format specifications of the form, { N [, M ][: formatString ]}, where:

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."

See also:
Object | IFormattable | MSDN: formattingoverview

Return to top


Overloaded Method: Format(
   string format,
   object arg0,
   object arg1,
   object arg2
)
Summary
Replaces the format specification in a specified String with the textual equivalent of the value of three specified Object instances.
C# Syntax:
public static string Format(
   string format,
   object arg0,
   object arg1,
   object arg2
);
Parameters:

format

A String containing zero or more format specifications.

arg0

The first Object to be formatted.

arg1

The second Object to be formatted.

arg2

The third Object to be formatted.

Return Value:
A copy of format in which the first, second, and third format specifications have been replaced by the String equivalent of the arg0,arg1, and arg2.
Exceptions
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.

Remarks
The format parameter is embedded with zero or more format specifications of the form, { N [, M ][: formatString ]}, where:

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."

See also:
Object | IFormattable | MSDN: formattingoverview

Return to top


Method: GetEnumerator()
Summary
Retrieves an object that can iterate through the individual characters in this instance.
C# Syntax:
public CharEnumerator GetEnumerator();
Return Value:
A CharEnumerator object.
Remarks
This method is required by programming languages that support the IEnumerator interface to iterate through members of a collection. For example, the Microsoft Visual Basic and C# programming languages' foreach statement invokes this method to return a CharEnumerator object that can provide read-only access to the characters in this instance of String.
See also:
IEnumerator | IEnumerable | String.Chars

Return to top


Overridden Method: GetHashCode()
Summary
Returns the hash code for this instance.
C# Syntax:
public override int GetHashCode();
Return Value:
A 32-bit signed integer hash code.
See also:
Int32

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetTypeCode()
Summary
Returns the TypeCode for class String.
C# Syntax:
public TypeCode GetTypeCode();
Return Value:
The enumerated constant, TypeCode.String.
Implements:
IConvertible.GetTypeCode

Return to top


Overloaded Method: IndexOf(
   char value
)
Summary
Reports the index of the first occurrence of the specified Unicode character in this instance.
C# Syntax:
public int IndexOf(
   char value
);
Parameters:

value

A Unicode character to seek.

Return Value:
A positive 32-bit signed integer, the index, that is the character position in this instance where value was found; otherwise, -1 if value was not found.
Remarks
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.

See also:
Char | String.IndexOfAny | String.LastIndexOf | String.LastIndexOfAny

Return to top


Overloaded Method: IndexOf(
   string value
)
Summary
Reports the index of the first occurrence of the specified String in this instance.
C# Syntax:
public int IndexOf(
   string value
);
Parameters:

value

The String to seek.

Return Value:


Value Meaning
A positive index position. was found.
0 is String.Empty .
-1 was not found.
Exceptions
Exception Type Condition
ArgumentNullException value is null.
Remarks
The search begins at the first character position of this instance and continues until the last character position. The search is case-sensitive and uses the current culture.
See also:
Int32 | CultureInfo | String.IndexOfAny | String.LastIndexOf | String.LastIndexOfAny

Return to top


Overloaded Method: IndexOf(
   char value,
   int startIndex
)
Summary
Reports the index of the first occurrence of the specified Unicode character in this instance. The search starts at a specified character position.
C# Syntax:
public int IndexOf(
   char value,
   int startIndex
);
Parameters:

value

A Unicode character to seek.

startIndex

The search starting position.

Return Value:
A positive 32-bit signed integer, the index, indicating the character position in this instance where value was found; otherwise, -1 if value was not found.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException startIndex is less than zero or specifies a position beyond the end of this instance.
Remarks
Index numbering starts from zero.

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.

See also:
Int32 | Char | String.IndexOfAny | String.LastIndexOf | String.LastIndexOfAny

Return to top


Overloaded Method: IndexOf(
   string value,
   int startIndex
)
Summary
Reports the index of the first occurrence of the specified String in this instance. The search starts at a specified character position.
C# Syntax:
public int IndexOf(
   string value,
   int startIndex
);
Parameters:

value

The String to seek.

startIndex

The search starting position.

Return Value:


Value Meaning
A positive index position. was found.
is String.Empty .
-1 was not found.
Exceptions
Exception Type Condition
ArgumentNullException anyOf is null.
ArgumentOutOfRangeException startIndex is negative.

-or-

startIndex specifies a position not within this instance.

Remarks
The search begins at the startIndex character position of this instance and continues until the last character position. The search is case-sensitive and uses the current culture.
See also:
Int32 | CultureInfo | String.IndexOfAny | String.LastIndexOf | String.LastIndexOfAny

Return to top


Overloaded Method: IndexOf(
   char value,
   int startIndex,
   int count
)
Summary
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.
C# Syntax:
public int IndexOf(
   char value,
   int startIndex,
   int count
);
Parameters:

value

A Unicode character to seek.

startIndex

The search starting position.

count

The number of character positions to examine.

Return Value:
A positive 32-bit signed integer, the index, that is the character position in this instance where value was found; otherwise, -1 if value was not found.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException count or startIndex is negative.

-or-

count + startIndex specifies a position beyond the end of this instance.

Remarks
The search begins at startIndex and continues to startIndex + count -1. The character at startIndex + count is not included in the search.

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.

See also:
Char | Int32 | String.IndexOfAny | String.LastIndexOf | String.LastIndexOfAny

Return to top


Overloaded Method: IndexOf(
   string value,
   int startIndex,
   int count
)
Summary
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.
C# Syntax:
public int IndexOf(
   string value,
   int startIndex,
   int count
);
Parameters:

value

The String to seek.

startIndex

The search starting position.

count

The number of character positions to examine.

Return Value:


Value Meaning
A positive index position. was found.
is String.Empty .
-1 was not found.
Exceptions
Exception Type Condition
ArgumentNullException value is null.
ArgumentOutOfRangeException count or startIndex is negative.

-or-

count plus startIndex specify a position not within this instance.

Remarks
The search begins at startIndex and continues to startIndex + count -1. The character at startIndex + count is not included in the search.

The search is case-sensitive and uses the current culture.

See also:
Int32 | CultureInfo | String.IndexOfAny | String.LastIndexOf | String.LastIndexOfAny

Return to top


Overloaded Method: IndexOfAny(
   char[] anyOf
)
Summary
Reports the index of the first occurrence in this instance of any character in a specified array of Unicode characters.
C# Syntax:
public int IndexOfAny(
   char[] anyOf
);
Parameters:

anyOf

A Unicode character array containing one or more characters to seek.

Return Value:
The positive integer index of the first occurrence in this instance where any character in anyOf was found; otherwise, -1 if no character in anyOf was found.
Exceptions
Exception Type Condition
ArgumentNullException anyOf is null.
Remarks
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.

See also:
Char | Int32 | Array | String.IndexOf | String.LastIndexOf | String.LastIndexOfAny

Return to top


Overloaded Method: IndexOfAny(
   char[] anyOf,
   int startIndex
)
Summary
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.
C# Syntax:
public int IndexOfAny(
   char[] anyOf,
   int startIndex
);
Parameters:

anyOf

A Unicode character array containing one or more characters to seek.

startIndex

The search starting position.

Return Value:
The positive integer index of the first occurrence in this instance where any character in anyOf was found; otherwise, -1 if no character in anyOf was found.
Exceptions
Exception Type Condition
ArgumentNullException anyOf is null.
ArgumentOutOfRangeException startIndex is negative.

-or-

startIndex is greater than the number of characters in this instance.

Remarks
Index numbering starts from zero.

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.

See also:
Char | Int32 | Array | String.IndexOf | String.LastIndexOf | String.LastIndexOfAny

Return to top


Overloaded Method: IndexOfAny(
   char[] anyOf,
   int startIndex,
   int count
)
Summary
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.
C# Syntax:
public int IndexOfAny(
   char[] anyOf,
   int startIndex,
   int count
);
Parameters:

anyOf

A Unicode character array containing one or more characters to seek.

startIndex

The search starting position.

count

The number of character positions to examine.

Return Value:
The positive integer index of the first occurrence in this instance where any character in anyOf was found; otherwise, -1 if no character in anyOf was found.
Exceptions
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.

Remarks
The search begins at startIndex and continues to startIndex + count -1. The character at startIndex + count is not included in the search.

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.

See also:
Char | Int32 | Array | String.IndexOf | String.LastIndexOf | String.LastIndexOfAny

Return to top


Method: Insert(
   int startIndex,
   string value
)
Summary
Inserts a specified instance of String at a specified index position in this instance.
C# Syntax:
public string Insert(
   int startIndex,
   string value
);
Parameters:

startIndex

The index position of the insertion.

value

The String to insert.

Return Value:
A new String equivalent to this instance but with value inserted at position startIndex.
Exceptions
Exception Type Condition
ArgumentNullException value is null.
ArgumentOutOfRangeException startIndex is negative or greater than the length of this instance.
Remarks
If startIndex is equal to the length of this instance, value is appended to the end of this instance.

For example, the return value of "abc".Insert(2, "XYZ") is "abXYZc".

See also:
Int32 | String.Concat | String.CopyTo | String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Substring | String.Trim

Return to top


Method: Intern(
   string str
)
Summary
Retrieves the system's reference to the specified String.
C# Syntax:
public static string Intern(
   string str
);
Parameters:

str

A String, or null.

Return Value:
The String reference to str.
Exceptions
Exception Type Condition
ArgumentNullException str is null.
Remarks
The common language runtime automatically maintains a table, called the "intern pool", which contains a single instance of each unique literal string constant declared in a program, as well as any unique instance of String you add programmatically.

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.

See also:
String.IsInterned

Return to top


Method: IsInterned(
   string str
)
Summary
Retrieves a reference to a specified String.
C# Syntax:
public static string IsInterned(
   string str
);
Parameters:

str

A String.

Return Value:
A String reference to str if it is in the common language runtime "intern pool"; otherwise null.
Exceptions
Exception Type Condition
ArgumentNullException str is null.
Remarks
The common language runtime automatically maintains a table, called the "intern pool", which contains a single instance of each unique literal string constant declared in a program, as well as any unique instance of String you add programmatically.

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.

See also:
String.Intern

Return to top


Overloaded Method: Join(
   string separator,
   string[] value
)
Summary
Concatenates a specified separator String between each element of a specified String array, yielding a single concatenated string.
C# Syntax:
public static string Join(
   string separator,
   string[] value
);
Parameters:

separator

A String.

value

An array of String s.

Return Value:
A String consisting of the elements of value interspersed with the separator string.
Exceptions
Exception Type Condition
ArgumentNullException value is null.
Remarks
For example if separator is ", " and the elements of value are "apple", "orange", "grape", and "pear", Join(separator, value) returns "apple, orange, grape, pear".
See also:
String.Concat | String.Insert | String.Remove | String.Replace | String.Split | String.Substring | String.Trim

Return to top


Overloaded Method: Join(
   string separator,
   string[] value,
   int startIndex,
   int count
)
Summary
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.
C# Syntax:
public static string Join(
   string separator,
   string[] value,
   int startIndex,
   int count
);
Parameters:

separator

A String.

value

An array of String.

startIndex

The first array element in value to use.

count

The number of elements of value to use.

Return Value:
A String consisting of the strings in value joined by separator.

-or-

String.Empty if count is zero, value has no elements, or separator and all the elements of value are String.Empty.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException startIndex plus count is greater than the number of elements in value.
Remarks
For example if separator is ", " and the elements of value are "apple", "orange", "grape", and "pear", Join(separator, value, 1, 2) returns "orange, grape".
See also:
Int32 | String.Concat | String.Insert | String.Remove | String.Replace | String.Split | String.Substring | String.Trim

Return to top


Overloaded Method: LastIndexOf(
   char value
)
Summary
Reports the index position of the last occurrence of a specified Unicode character within this instance.
C# Syntax:
public int LastIndexOf(
   char value
);
Parameters:

value

A Unicode character to seek.

Return Value:
The index position of value if that character is found, or -1 if it is not.
Exceptions
Exception Type Condition
ArgumentNullException value is null.
Remarks
This method begins searching at the last character position of this instance and precedes backwards towards the beginning until either value is found or the first character position has been examined. The search is case-sensitive.
See also:
Char | String.IndexOf | String.IndexOfAny | String.LastIndexOfAny

Return to top


Overloaded Method: LastIndexOf(
   string value
)
Summary
Reports the index position of the last occurrence of a specified String within this instance.
C# Syntax:
public int LastIndexOf(
   string value
);
Parameters:

value

A String to seek.

Return Value:


Value Meaning
A positive index position. was found.
0 is String.Empty .
-1 was not found.
Exceptions
Exception Type Condition
ArgumentNullException value is null.
Remarks
This method begins searching at the last character position of this instance and precedes backwards towards the beginning until either value is found or the first character position has been examined. The search is case-sensitive.
See also:
Int32 | String.IndexOf | String.IndexOfAny | String.LastIndexOfAny

Return to top


Overloaded Method: LastIndexOf(
   char value,
   int startIndex
)
Summary
Reports the index position of the last occurrence of a specified Unicode character within this instance. The search starts at a specified character position.
C# Syntax:
public int LastIndexOf(
   char value,
   int startIndex
);
Parameters:

value

A Unicode character to seek.

startIndex

The starting position of a substring within this instance.

Return Value:
The index position of value if that character is found, or -1 if it is not.
Exceptions
Exception Type Condition
ArgumentNullException value is null.
ArgumentOutOfRangeException startIndex is less than zero or greater than the length of this instance.
Remarks
This method begins searching at the startIndex character position of this instance and precedes backwards towards the beginning until either value is found or the first character position has been examined. The search is case-sensitive.
See also:
Char | Int32 | String.IndexOf | String.IndexOfAny | String.LastIndexOfAny

Return to top


Overloaded Method: LastIndexOf(
   string value,
   int startIndex
)
Summary
Reports the index position of the last occurrence of a specified String within this instance. The search starts at a specified character position.
C# Syntax:
public int LastIndexOf(
   string value,
   int startIndex
);
Parameters:

value

The String to seek.

startIndex

The search starting position.

Return Value:


Value Meaning
A positive index position. was found.
is String.Empty .
-1 was not found.
Exceptions
Exception Type Condition
ArgumentNullException value is null.
ArgumentOutOfRangeException startIndex is less than zero or specifies a position not within this instance.
Remarks
This method begins searching at the startIndex character position of this instance and precedes backwards towards the beginning until either value is found or the first character position has been examined. The search is case-sensitive.
See also:
Int32 | String.IndexOf | String.IndexOfAny | String.LastIndexOfAny

Return to top


Overloaded Method: LastIndexOf(
   char value,
   int startIndex,
   int count
)
Summary
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.
C# Syntax:
public int LastIndexOf(
   char value,
   int startIndex,
   int count
);
Parameters:

value

A Unicode character to seek.

startIndex

The starting position of a substring within this instance.

count

The number of character positions to examine.

Return Value:
The index position of value if that character is found, or -1 if it is not.
Exceptions
Exception Type Condition
ArgumentNullException value is null.
ArgumentOutOfRangeException startIndex or count is less than zero or greater than the length of this instance.
Remarks
This method begins searching at the startIndex character position of this instance and precedes backwards towards the beginning until either value is found or count character positions have been examined. The search is case-sensitive.
See also:
Char | Int32 | String.IndexOf | String.IndexOfAny | String.LastIndexOfAny

Return to top


Overloaded Method: LastIndexOf(
   string value,
   int startIndex,
   int count
)
Summary
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.
C# Syntax:
public int LastIndexOf(
   string value,
   int startIndex,
   int count
);
Parameters:

value

The String to seek.

startIndex

The search starting position.

count

The number of character positions to examine.

Return Value:


Value Meaning
A positive index position. was found.
is String.Empty .
-1 was not found.
Exceptions
Exception Type Condition
ArgumentNullException value is null.
ArgumentOutOfRangeException count or startIndex is negative.

-or-

count plus startIndex specify a position not within this instance.

Remarks
This method begins searching at the startIndex character position of this instance and precedes backwards towards the beginning until either value is found or count character positions have been examined. The search is case-sensitive.
See also:
Int32 | String.IndexOf | String.IndexOfAny | String.LastIndexOfAny

Return to top


Overloaded Method: LastIndexOfAny(
   char[] anyOf
)
Summary
Reports the index position of the last occurrence in this instance of one or more characters specified in a Unicode array.
C# Syntax:
public int LastIndexOfAny(
   char[] anyOf
);
Parameters:

anyOf

A Unicode character array containing one or more characters to seek.

Return Value:
The positive integer index of the last occurrence in this instance where any character in anyOf was found; otherwise, -1 if no character in anyOf was found.
Exceptions
Exception Type Condition
ArgumentNullException anyOf is null.
Remarks
This method begins searching at the last character position of this instance and precedes backwards towards the beginning until either a character in anyOf is found or the first character position has been examined. The search 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.

See also:
Char | Int32 | Array | String.IndexOf | String.IndexOfAny | String.LastIndexOf

Return to top


Overloaded Method: LastIndexOfAny(
   char[] anyOf,
   int startIndex
)
Summary
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.
C# Syntax:
public int LastIndexOfAny(
   char[] anyOf,
   int startIndex
);
Parameters:

anyOf

A Unicode character array containing one or more characters to seek.

startIndex

The search starting position.

Return Value:
The positive integer index of the last occurrence in this instance where any character in anyOf was found; otherwise, -1 if no character in anyOf was found.
Exceptions
Exception Type Condition
ArgumentNullException anyOf is null.
ArgumentOutOfRangeException startIndex specifies a position not within this instance.
Remarks
This method begins searching at the startIndex character position of this instance and precedes backwards towards the beginning until either a character in anyOf is found or the first character position has been examined. The search 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.

See also:
Char | Int32 | Array | String.IndexOf | String.IndexOfAny | String.LastIndexOf

Return to top


Overloaded Method: LastIndexOfAny(
   char[] anyOf,
   int startIndex,
   int count
)
Summary
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.
C# Syntax:
public int LastIndexOfAny(
   char[] anyOf,
   int startIndex,
   int count
);
Parameters:

anyOf

A Unicode character array containing one or more characters to seek.

startIndex

The search starting position.

count

The number of character positions to examine.

Return Value:
The positive integer index of the last occurrence in this instance where any character in anyOf was found; otherwise, -1 if no character in anyOf was found.
Exceptions
Exception Type Condition
ArgumentNullException anyOf is null.
ArgumentOutOfRangeException count or startIndex is negative.

-or-

count plus startIndex specify a position not within this instance.

Remarks
This method begins searching at the startIndex character position of this instance and precedes backwards towards the beginning until either a character in anyOf is found or count character positions have been examined. The search 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.

See also:
Char | Int32 | Array | String.IndexOf | String.IndexOfAny | String.LastIndexOf

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: op_Equality(
   string a,
   string b
)
Summary
Determines whether two specified String objects have the same value.
C# Syntax:
public static bool operator ==(
   string a,
   string b
);
Parameters:

a

A String or null.

b

A String or null.

Return Value:
true if the value of a is the same as the value of b; otherwise, false.
Remarks
This operator is implemented using the String.Equals method, which means the comparands are tested for a combination of reference and value equality. The comparison is case-sensitive.

Return to top


Method: op_Inequality(
   string a,
   string b
)
Summary
Determines whether two specified String objects have different values.
C# Syntax:
public static bool operator !=(
   string a,
   string b
);
Parameters:

a

A String or null.

b

A String or null.

Return Value:
true if the value of a is different from the value of b; otherwise, false.
Remarks
This operator is implemented using the String.Equals method, which means the comparands are tested for a combination of reference and value equality. The comparison is case-sensitive.

Return to top


Overloaded Method: PadLeft(
   int totalWidth
)
Summary
Right-aligns the characters in this instance, padding with spaces on the left for a specified total length.
C# Syntax:
public string PadLeft(
   int totalWidth
);
Parameters:

totalWidth

The number of characters in the resulting string, equal to the number of original characters plus any additional padding characters.

Return Value:
A new String that is equivalent to this instance, but right-aligned and padded on the left with as many spaces as needed to create a length of totalWidth.

-or-

If totalWidth is less than the length of this instance, a new String that is identical to this instance.
Exceptions
Exception Type Condition
ArgumentException totalWidth is less than zero.
Remarks
A Unicode space is defined as hexadecimal 0x20.
Example
See also:
Int32 | String.PadRight | String.Trim

Return to top


Overloaded Method: PadLeft(
   int totalWidth,
   char paddingChar
)
Summary
Right-aligns the characters in this instance, padding on the left with a specified Unicode character for a specified total length.
C# Syntax:
public string PadLeft(
   int totalWidth,
   char paddingChar
);
Parameters:

totalWidth

The number of characters in the resulting string, equal to the number of original characters plus any additional padding characters.

paddingChar

A Unicode padding character.

Return Value:
A new String that is equivalent to this instance, but right-aligned and padded on the left with as many paddingChar characters as needed to create a length of totalWidth.

-or-

If totalWidth is less than the length of this instance, a new String that is identical to this instance.
Exceptions
Exception Type Condition
ArgumentException totalWidth is less than zero.
Example
See also:
Char | Int32 | String.PadRight | String.Trim

Return to top


Overloaded Method: PadRight(
   int totalWidth
)
Summary
Left-aligns the characters in this string, padding with spaces on the right, for a specified total length.
C# Syntax:
public string PadRight(
   int totalWidth
);
Parameters:

totalWidth

The number of characters in the resulting string, equal to the number of original characters plus any additional padding characters.

Return Value:
A new String that is equivalent to this instance, but left-aligned and padded on the right with as many spaces as needed to create a length of totalWidth.

-or-

If totalWidth is less than the length of this instance, a new String that is identical to this instance.

Exceptions
Exception Type Condition
ArgumentException totalWidth is less than zero.
Remarks
A Unicode space is defined as hexadecimal 0x20.
Example
See also:
Int32 | String.PadLeft | String.Trim

Return to top


Overloaded Method: PadRight(
   int totalWidth,
   char paddingChar
)
Summary
Left-aligns the characters in this string, padding on the right with a specified Unicode character, for a specified total length.
C# Syntax:
public string PadRight(
   int totalWidth,
   char paddingChar
);
Parameters:

totalWidth

The number of characters in the resulting string, equal to the number of original characters plus any additional padding characters.

paddingChar

A Unicode padding character.

Return Value:
A new String that is equivalent to this instance, but left-aligned and padded on the right with as many paddingChar characters as needed to create a length of totalWidth.

-or-

If totalWidth is less than the length of this instance, a new String that is identical to this instance.

Exceptions
Exception Type Condition
ArgumentException totalWidth is less than zero.
Example
See also:
Char | Int32 | String.PadLeft | String.Trim

Return to top


Method: Remove(
   int startIndex,
   int count
)
Summary
Deletes a specified number of characters from this instance beginning at a specified position.
C# Syntax:
public string Remove(
   int startIndex,
   int count
);
Parameters:

startIndex

The position in this instance to begin deleting characters.

count

The number of characters to delete.

Return Value:
A new String that is equivalent to this instance less count number of characters.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException Either startIndex or count is less than zero.

-or-

startIndex plus count is greater than the length of this instance.

Remarks
For example, the following C# code prints "123456".

String s = "123abc456";

Console.WriteLine(s.Remove(3, 3));

See also:
Int32 | String.Concat | String.Insert | String.Join | String.Replace | String.Split | String.Substring | String.Trim

Return to top


Overloaded Method: Replace(
   char oldChar,
   char newChar
)
Summary
Replaces all occurrences of a specified Unicode character in this instance with another specified Unicode character.
C# Syntax:
public string Replace(
   char oldChar,
   char newChar
);
Parameters:

oldChar

A Unicode character to be replaced.

newChar

A Unicode character to replace all occurrences of oldChar.

Return Value:
A String equivalent to this instance but with all instances of oldChar replaced with newChar.
See also:
Char | String.Concat | String.Insert | String.Join | String.Remove | String.Split | String.Substring | String.Trim

Return to top


Overloaded Method: Replace(
   string oldValue,
   string newValue
)
Summary
Replaces all occurrences of a specified String in this instance, with another specified String.
C# Syntax:
public string Replace(
   string oldValue,
   string newValue
);
Parameters:

oldValue

A String to be replaced.

newValue

A String to replace all occurrences of oldValue.

Return Value:
A String equivalent to this instance but with all instances of oldValue replaced with newValue.
Remarks
If newValue is null, oldValue is removed.
See also:
String.Concat | String.Insert | String.Join | String.Remove | String.Split | String.Substring | String.Trim

Return to top


Overloaded Method: Split(
   params char[] separator
)
Summary
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.
C# Syntax:
public string[] Split(
   params char[] separator
);
Parameters:

separator

An array of Unicode characters that delimit the substrings in this instance, an empty array containing no delimiters, or null.

Return Value:
An array consisting of a single element containing this instance, if this instance contains none of the characters in 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.

Remarks
For example:

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"}
See also:
Char | String.Concat | String.Insert | String.Join | String.Remove | String.Replace | String.Substring | String.Trim

Return to top


Overloaded Method: Split(
   char[] separator,
   int count
)
Summary
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.
C# Syntax:
public string[] Split(
   char[] separator,
   int count
);
Parameters:

separator

An array of Unicode characters that delimit the substrings in this instance, an empty array containing no delimiters, or null.

count

The maximum number of array elements to return.

Return Value:
An array consisting of a single element containing this instance, if this instance contains none of the characters in 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.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException count is negative.
Remarks
If there are more than count substrings in this instance, the first count minus 1 substrings are returned in the first count minus 1 elements of the return value, and the remaining characters in this instance are returned in the last element of the return value.

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"}
See also:
Char | Array | Int32 | String.Concat | String.Insert | String.Join | String.Remove | String.Replace | String.Substring | String.Trim

Return to top


Method: StartsWith(
   string value
)
Summary
Determines whether the beginning of this instance matches the specified String.
C# Syntax:
public bool StartsWith(
   string value
);
Parameters:

value

The String to seek.

Return Value:
true if value matches the beginning of this string or is String.Empty; otherwise false.
Exceptions
Exception Type Condition
ArgumentNullException value is null.
Remarks
This method makes a comparison at the beginning of the string, determines whether it matches this current instance, and returns a Boolean represetation of their relationship. The specified string must match the prefix or be an empty string (that is, equals String.Empty). The comparison is case-sensitive.
See also:
String.EndsWith

Return to top


Overloaded Method: Substring(
   int startIndex
)
Summary
Retrieves a substring from this instance. The substring starts at a specified character position.
C# Syntax:
public string Substring(
   int startIndex
);
Parameters:

startIndex

The starting character position of a substring in this instance.

Return Value:
A String equivalent to the substring that begins at startIndex in this instance.

-or-

String.Empty if startIndex is equal to the length of this instance.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException startIndex is less than zero or greater than the length of this instance.
Remarks
The index is zero-based.
See also:
Int32 | String.Concat | String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Trim

Return to top


Overloaded Method: Substring(
   int startIndex,
   int length
)
Summary
Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length.
C# Syntax:
public string Substring(
   int startIndex,
   int length
);
Parameters:

startIndex

The index of the start of the substring.

length

The number of characters in the substring.

Return Value:
A String equivalent to the substring of length length that begins at startIndex in this instance.

-or-

String.Empty if startIndex is equal to the length of this instance and length is zero.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException startIndex plus length indicates a position not within this instance.

-or-

startIndex or length is less than zero.

Remarks
startIndex is zero-based.
Example
        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.

    
See also:
Int32 | String.Concat | String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Trim

Return to top


Overloaded Method: ToCharArray()
Summary
Copies the characters in this instance to a Unicode character array.
C# Syntax:
public char[] ToCharArray();
Return Value:
A Unicode character array whose elements are the individual characters of this instance. If this instance is an empty string, the returned array is empty and has a zero length.
See also:
Char | Array

Return to top


Overloaded Method: ToCharArray(
   int startIndex,
   int length
)
Summary
Copies the characters in a specified substring in this instance to a Unicode character array.
C# Syntax:
public char[] ToCharArray(
   int startIndex,
   int length
);
Parameters:

startIndex

The starting position of a substring in this instance.

length

The length of the substring in this instance.

Return Value:
A Unicode character array whose elements are the length number of characters in this instance starting from character position startIndex.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException startIndex or length is less than zero.

-or-

startIndex plus length is greater than the length of this instance.

Remarks
If length is zero, the entire string is copied starting from the beginning of this instance, and ignoring the value of startIndex. If this instance is an empty string, the returned array is empty and has a zero length.
See also:
Array | Char | Int32

Return to top


Overloaded Method: ToLower()
Summary
Returns a copy of this String in lowercase.
C# Syntax:
public string ToLower();
Return Value:
A String in lowercase.
Remarks
This method takes into account the current CultureInfo information.
See also:
String.ToUpper

Return to top


Overloaded Method: ToLower(
   CultureInfo culture
)
Summary
Returns a copy of this String in lowercase, taking into account specified culture-specific information.
C# Syntax:
public string ToLower(
   CultureInfo culture
);
Parameters:

culture

A CultureInfo object that supplies culture-specific formatting information.

Return Value:
A String in lowercase.
Exceptions
Exception Type Condition
ArgumentNullException culture is null.
See also:
CultureInfo | String.ToUpper

Return to top


Overloaded Method: ToString()
Summary
Returns this instance of String; no actual conversion is performed.
C# Syntax:
public override string ToString();
Return Value:
This String.

Return to top


Overloaded Method: ToString(
   IFormatProvider provider
)
Summary
Returns this instance of String; no actual conversion is performed.
C# Syntax:
public string ToString(
   IFormatProvider provider
);
Parameters:

provider

(Reserved) An IFormatProvider that supplies culture-specific formatting information.

Return Value:
This String.
Implements:
IConvertible.ToString
Remarks
provider is reserved, and does not currently participate in this operation.

Return to top


Overloaded Method: ToUpper()
Summary
Returns a copy of this String in uppercase, using default properties.
C# Syntax:
public string ToUpper();
Return Value:
A String in uppercase.
Remarks
This method takes into account the current CultureInfo information.
See also:
String.ToLower

Return to top


Overloaded Method: ToUpper(
   CultureInfo culture
)
Summary
Returns a copy of this String in uppercase, taking into account culture-specific information.
C# Syntax:
public string ToUpper(
   CultureInfo culture
);
Parameters:

culture

A CultureInfo object that supplies culture-specific formatting information.

Return Value:
A String in uppercase.
Exceptions
Exception Type Condition
ArgumentNullException culture is null.
See also:
String.ToLower

Return to top


Overloaded Method: Trim()
Summary
Removes all occurrences of white space characters from the beginning and end of this instance.
C# Syntax:
public string Trim();
Return Value:
A new String equivalent to this instance after white space characters are removed.
Remarks
This method defines white space characters as hexadecimal 0x9, 0xA, 0xB, 0xC, 0xD, 0x20, 0xA0, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x200B, 0x3000, and 0xFEFF.
See also:
Char | String.Concat | String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Substring | String.TrimEnd | String.TrimStart

Return to top


Overloaded Method: Trim(
   params char[] trimChars
)
Summary
Removes all occurrences of a set of characters specified in a Unicode character array from the beginning and end of this instance.
C# Syntax:
public string Trim(
   params char[] trimChars
);
Parameters:

trimChars

An array of Unicode characters to be removed or null.

Return Value:
The String that remains after all occurrences of the characters in trimChars are removed. If trimChars is null, white space characters are removed instead.
Remarks
This method defines white space characters as hexadecimal 0x9, 0xA, 0xB, 0xC, 0xD, 0x20, 0xA0, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x200B, 0x3000, and 0xFEFF.
See also:
Char | String.Concat | String.Insert | String.Join | String.Remove | String.Replace | String.Split | String.Substring | String.TrimEnd | String.TrimStart

Return to top


Method: TrimEnd(
   params char[] trimChars
)
Summary
Removes all occurrences of a set of characters specified in a Unicode character array from the end of this instance.
C# Syntax:
public string TrimEnd(
   params char[] trimChars
);
Parameters:

trimChars

An array of Unicode characters to be removed or null.

Return Value:
The String that remains after all occurrences of the characters in trimChars are removed. If trimChars is null, white space characters are removed instead.
Remarks
This method defines white space characters as hexadecimal 0x9, 0xA, 0xB, 0xC, 0xD, 0x20, 0xA0, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x200B, 0x3000, and 0xFEFF.
See also:
Char | String.Trim | String.TrimStart

Return to top


Method: TrimStart(
   params char[] trimChars
)
Summary
Removes all occurrences of a set of characters specified in a Unicode character array from the beginning of this instance.
C# Syntax:
public string TrimStart(
   params char[] trimChars
);
Parameters:

trimChars

An array of Unicode characters to be removed or null.

Return Value:
The String that remains after all occurrences of characters in trimChars are removed. If trimChars is null, white space characters are removed instead.
Remarks
This method defines white space characters as hexadecimal 0x9, 0xA, 0xB, 0xC, 0xD, 0x20, 0xA0, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x200B, 0x3000, and 0xFEFF.
See also:
Char | String.Trim | String.TrimEnd

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.