System.Globalization.CompareInfo Class

Assembly: Mscorlib.dll
Namespace: System.Globalization
Summary
Implements a set of methods for culture-sensitive string comparisons.
C# Syntax:
[Serializable]
public class CompareInfo : IDeserializationCallback
Remarks
The CultureInfo class includes a CultureInfo.CompareInfo property that is an instance of this class. String.Compare uses the information in CultureInfo.CompareInfo to compare strings.

Unlike most classes, CompareInfo provides the CompareInfo.GetCompareInfo method, instead of public constructors, to allow for late-bound access.

To create a CompareInfo for any culture, use the CultureInfo.CompareInfo property, or use the CompareInfo.GetCompareInfo method.

See also:
System.Globalization Namespace

System.Globalization.CompareInfo Member List:

Public Properties
LCID Read-only

Gets the properly formed culture identifier for the current CompareInfo.
Public Methods
Compare Overloaded:
Compare(string string1, string string2)

Compares two strings using the default CompareOptions value.
Compare Overloaded:
Compare(string string1, string string2, CompareOptions options)

Compares two strings using the specified CompareOptions value.
Compare Overloaded:
Compare(string string1, int offset1, string string2, int offset2)

Compares the end section of a string with the end section of another string.
Compare Overloaded:
Compare(string string1, int offset1, string string2, int offset2, CompareOptions options)

Compares the end section of a string with the end section of another string using the specified CompareOptions value.
Compare Overloaded:
Compare(string string1, int offset1, int length1, string string2, int offset2, int length2)

Compares a section of one string with a section of another string.
Compare Overloaded:
Compare(string string1, int offset1, int length1, string string2, int offset2, int length2, CompareOptions options)

Compares a section of one string with a section of another string using the specified CompareOptions value.
Equals Overridden:
Determines whether the specified object is the same instance as the current CompareInfo.
GetCompareInfo Overloaded:
GetCompareInfo(int culture)

Initializes a new instance of the CompareInfo class that is associated with the culture having the specified identifier.
GetCompareInfo Overloaded:
GetCompareInfo(string name)

Initializes a new instance of the CompareInfo class that is associated with the culture having the specified name.
GetCompareInfo Overloaded:
GetCompareInfo(int culture, Assembly assembly)

Initializes a new instance of the CompareInfo class that is associated with the culture having the specified identifier and uses string comparison methods in the specified Assembly.
GetCompareInfo Overloaded:
GetCompareInfo(string name, Assembly assembly)

Initializes a new instance of the CompareInfo class that is associated with the culture having the specified name and uses string comparison methods in the specified Assembly.
GetHashCode Overridden:
Serves as a hash function for the current CompareInfo for use in hashing algorithms and data structures, such as a hash table.
GetSortKey Overloaded:
GetSortKey(string source)

Gets the SortKey of the specified string.
GetSortKey Overloaded:
GetSortKey(string source, CompareOptions options)

Gets the SortKey of the specified string using the specified CompareOptions value.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
IndexOf Overloaded:
IndexOf(string source, char value)

Searches for the specified character and returns the zero-based index of the first occurrence within the entire source string.
IndexOf Overloaded:
IndexOf(string source, string value)

Searches for the specified substring and returns the zero-based index of the first occurrence within the entire source string.
IndexOf Overloaded:
IndexOf(string source, char value, CompareOptions options)

Searches for the specified character and returns the zero-based index of the first occurrence within the entire source string using the specified CompareOptions value.
IndexOf Overloaded:
IndexOf(string source, char value, int startIndex)

Searches for the specified character and returns the zero-based index of the first occurrence within the section of the source string that extends from the specified index to the end of the string.
IndexOf Overloaded:
IndexOf(string source, string value, CompareOptions options)

Searches for the specified substring and returns the zero-based index of the first occurrence within the entire source string using the specified CompareOptions value.
IndexOf Overloaded:
IndexOf(string source, string value, int startIndex)

Searches for the specified substring and returns the zero-based index of the first occurrence within the section of the source string that extends from the specified index to the end of the string.
IndexOf Overloaded:
IndexOf(string source, char value, int startIndex, CompareOptions options)

Searches for the specified character and returns the zero-based index of the first occurrence within the section of the source string that extends from the specified index to the end of the string using the specified CompareOptions value.
IndexOf Overloaded:
IndexOf(string source, char value, int startIndex, int count)

Searches for the specified character and returns the zero-based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements.
IndexOf Overloaded:
IndexOf(string source, string value, int startIndex, CompareOptions options)

Searches for the specified substring and returns the zero-based index of the first occurrence within the section of the source string that extends from the specified index to the end of the string using the specified CompareOptions value.
IndexOf Overloaded:
IndexOf(string source, string value, int startIndex, int count)

Searches for the specified substring and returns the zero-based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements.
IndexOf Overloaded:
IndexOf(string source, char value, int startIndex, int count, CompareOptions options)

Searches for the specified character and returns the zero-based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements using the specified CompareOptions value.
IndexOf Overloaded:
IndexOf(string source, string value, int startIndex, int count, CompareOptions options)

Searches for the specified substring and returns the zero-based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements using the specified CompareOptions value.
IsPrefix Overloaded:
IsPrefix(string source, string prefix)

Determines whether the specified source string starts with the specified prefix.
IsPrefix Overloaded:
IsPrefix(string source, string prefix, CompareOptions options)

Determines whether the specified source string starts with the specified prefix using the specified CompareOptions value.
IsSuffix Overloaded:
IsSuffix(string source, string suffix)

Determines whether the specified source string ends with the specified suffix.
IsSuffix Overloaded:
IsSuffix(string source, string suffix, CompareOptions options)

Determines whether the specified source string ends with the specified suffix using the specified CompareOptions value.
LastIndexOf Overloaded:
LastIndexOf(string source, char value)

Searches for the specified character and returns the zero-based index of the last occurrence within the entire source string.
LastIndexOf Overloaded:
LastIndexOf(string source, string value)

Searches for the specified substring and returns the zero-based index of the last occurrence within the entire source string.
LastIndexOf Overloaded:
LastIndexOf(string source, char value, CompareOptions options)

Searches for the specified character and returns the zero-based index of the last occurrence within the entire source string using the specified CompareOptions value.
LastIndexOf Overloaded:
LastIndexOf(string source, char value, int startIndex)

Searches for the specified character and returns the zero-based index of the last occurrence within the section of the source string that extends from the beginning of the string to the specified index.
LastIndexOf Overloaded:
LastIndexOf(string source, string value, CompareOptions options)

Searches for the specified substring and returns the zero-based index of the last occurrence within the entire source string using the specified CompareOptions value.
LastIndexOf Overloaded:
LastIndexOf(string source, string value, int startIndex)

Searches for the specified substring and returns the zero-based index of the last occurrence within the section of the source string that extends from the beginning of the string to the specified index.
LastIndexOf Overloaded:
LastIndexOf(string source, char value, int startIndex, CompareOptions options)

Searches for the specified character and returns the zero-based index of the last occurrence within the section of the source string that extends from the beginning of the string to the specified index using the specified CompareOptions value.
LastIndexOf Overloaded:
LastIndexOf(string source, char value, int startIndex, int count)

Searches for the specified character and returns the zero-based index of the last occurrence within the section of the source string that contains the specified number of elements and ends at the specified index.
LastIndexOf Overloaded:
LastIndexOf(string source, string value, int startIndex, CompareOptions options)

Searches for the specified substring and returns the zero-based index of the last occurrence within the section of the source string that extends from the beginning of the string to the specified index using the specified CompareOptions value.
LastIndexOf Overloaded:
LastIndexOf(string source, string value, int startIndex, int count)

Searches for the specified substring and returns the zero-based index of the last occurrence within the section of the source string that contains the specified number of elements and ends at the specified index.
LastIndexOf Overloaded:
LastIndexOf(string source, char value, int startIndex, int count, CompareOptions options)

Searches for the specified character and returns the zero-based index of the last occurrence within the section of the source string that contains the specified number of elements and ends at the specified index using the specified CompareOptions value.
LastIndexOf Overloaded:
LastIndexOf(string source, string value, int startIndex, int count, CompareOptions options)

Searches for the specified substring and returns the zero-based index of the last occurrence within the section of the source string that contains the specified number of elements and ends at the specified index using the specified CompareOptions value.
ToString Overridden:
Returns a string that represents the current CompareInfo.
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.Globalization.CompareInfo Member Details

Property: LCID (read-only)
Summary
Gets the properly formed culture identifier for the current CompareInfo.
C# Syntax:
public int LCID {get;}

Return to top


Overloaded Method: Compare(
   string string1,
   string string2
)
Summary
Compares two strings using the default CompareOptions value.
C# Syntax:
public virtual int Compare(
   string string1,
   string string2
);
Parameters:

string1

The first string to compare.

string2

The second string to compare.

Return Value:


Value Condition
zero The two strings are equal.
less than zero is less than .
greater than zero is greater than .

Return to top


Overloaded Method: Compare(
   string string1,
   string string2,
   CompareOptions options
)
Summary
Compares two strings using the specified CompareOptions value.
C# Syntax:
public virtual int Compare(string string1, string string2, Compare(
   string string1,
   string string2,
   CompareOptions options
);
Parameters:

string1

The first string to compare.

string2

The second string to compare.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:


Value Condition
zero The two strings are equal.
less than zero is less than .
greater than zero is greater than .
Exceptions
Exception Type Condition
ArgumentException options is not a valid CompareOptions value.
See also:
CompareOptions

Return to top


Overloaded Method: Compare(
   string string1,
   int offset1,
   string string2,
   int offset2
)
Summary
Compares the end section of a string with the end section of another string.
C# Syntax:
public virtual int Compare(
   string string1,
   int offset1,
   string string2,
   int offset2
);
Parameters:

string1

The first string to compare.

offset1

The zero-based index of the character in string1 at which to start comparing.

string2

The second string to compare.

offset2

The zero-based index of the character in string2 at which to start comparing.

Return Value:


Value Condition
zero The two strings are equal.
less than zero The specified section of is less than the specified section of .
greater than zero The specified section of is greater than the specified section of .
Exceptions
Exception Type Condition
ArgumentOutOfRangeException offset1 or offset2 is less than zero.

-or-

offset1 is greater than or equal to the number of characters in string1.

-or-

offset2 is greater than or equal to the number of characters in string2.

Return to top


Overloaded Method: Compare(
   string string1,
   int offset1,
   string string2,
   int offset2,
   CompareOptions options
)
Summary
Compares the end section of a string with the end section of another string using the specified CompareOptions value.
C# Syntax:
public virtual int Compare(string string1, int offset1, string string2, int offset2, Compare(
   string string1,
   int offset1,
   string string2,
   int offset2,
   CompareOptions options
);
Parameters:

string1

The first string to compare.

offset1

The zero-based index of the character in string1 at which to start comparing.

string2

The second string to compare.

offset2

The zero-based index of the character in string2 at which to start comparing.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:


Value Condition
zero The two strings are equal.
less than zero The specified section of is less than the specified section of .
greater than zero The specified section of is greater than the specified section of .
Exceptions
Exception Type Condition
ArgumentOutOfRangeException offset1 or offset2 is less than zero.

-or-

offset1 is greater than or equal to the number of characters in string1.

-or-

offset2 is greater than or equal to the number of characters in string2.

ArgumentException options is not a valid CompareOptions value.
See also:
CompareOptions

Return to top


Overloaded Method: Compare(
   string string1,
   int offset1,
   int length1,
   string string2,
   int offset2,
   int length2
)
Summary
Compares a section of one string with a section of another string.
C# Syntax:
public virtual int Compare(
   string string1,
   int offset1,
   int length1,
   string string2,
   int offset2,
   int length2
);
Parameters:

string1

The first string to compare.

offset1

The zero-based index of the character in string1 at which to start comparing.

length1

The number of consecutive characters in string1 to compare.

string2

The second string to compare.

offset2

The zero-based index of the character in string2 at which to start comparing.

length2

The number of consecutive characters in string2 to compare.

Return Value:


Value Condition
zero The two strings are equal.
less than zero The specified section of is less than the specified section of .
greater than zero The specified section of is greater than the specified section of .
Exceptions
Exception Type Condition
ArgumentOutOfRangeException offset1 or length1 or offset2 or length2 is less than zero.

-or-

offset1 is greater than or equal to the number of characters in string1.

-or-

offset2 is greater than or equal to the number of characters in string2.

-or-

length1 is greater than the number of characters from offset1 to the end of string1.

-or-

length2 is greater than the number of characters from offset2 to the end of string2.

Return to top


Overloaded Method: Compare(
   string string1,
   int offset1,
   int length1,
   string string2,
   int offset2,
   int length2,
   CompareOptions options
)
Summary
Compares a section of one string with a section of another string using the specified CompareOptions value.
C# Syntax:
public virtual int Compare(string string1, int offset1, int length1, string string2, int offset2, int length2, Compare(
   string string1,
   int offset1,
   int length1,
   string string2,
   int offset2,
   int length2,
   CompareOptions options
);
Parameters:

string1

The first string to compare.

offset1

The zero-based index of the character in string1 at which to start comparing.

length1

The number of consecutive characters in string1 to compare.

string2

The second string to compare.

offset2

The zero-based index of the character in string2 at which to start comparing.

length2

The number of consecutive characters in string2 to compare.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:


Value Condition
zero The two strings are equal.
less than zero The specified section of is less than the specified section of .
greater than zero The specified section of is greater than the specified section of .
Exceptions
Exception Type Condition
ArgumentOutOfRangeException offset1 or length1 or offset2 or length2 is less than zero.

-or-

offset1 is greater than or equal to the number of characters in string1.

-or-

offset2 is greater than or equal to the number of characters in string2.

-or-

length1 is greater than the number of characters from offset1 to the end of string1.

-or-

length2 is greater than the number of characters from offset2 to the end of string2.

ArgumentException options is not a valid CompareOptions value.
See also:
CompareOptions

Return to top


Overridden Method: Equals(
   object value
)
Summary
Determines whether the specified object is the same instance as the current CompareInfo.
C# Syntax:
public override bool Equals(
   object value
);
Parameters:

value

The object to compare with the current CompareInfo.

Return Value:
true if the specified object is the same instance as the current CompareInfo; otherwise, false.
Remarks
This method overrides Object.Equals.
See also:
Object.Equals

Return to top


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

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

Return to top


Overloaded Method: GetCompareInfo(
   int culture
)
Summary
Initializes a new instance of the CompareInfo class that is associated with the culture having the specified identifier.
C# Syntax:
public static CompareInfo GetCompareInfo(
   int culture
);
Parameters:

culture

An integer representing the culture identifier.

Return Value:
A new instance of the CompareInfo class that is associated with the culture having the specified identifier and uses string comparison methods in the current Assembly.

Return to top


Overloaded Method: GetCompareInfo(
   string name
)
Summary
Initializes a new instance of the CompareInfo class that is associated with the culture having the specified name.
C# Syntax:
public static CompareInfo GetCompareInfo(
   string name
);
Parameters:

name

A string representing the culture name.

Return Value:
A new instance of the CompareInfo class that is associated with the culture having the specified name and uses string comparison methods in the current Assembly.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
ArgumentException name is an invalid culture name.

Return to top


Overloaded Method: GetCompareInfo(
   int culture,
   Assembly assembly
)
Summary
Initializes a new instance of the CompareInfo class that is associated with the culture having the specified identifier and uses string comparison methods in the specified Assembly.
C# Syntax:
public static CompareInfo GetCompareInfo(
   int culture,
   Assembly assembly
);
Parameters:

culture

An integer representing the culture identifier.

assembly

An Assembly that contains the string comparison methods to use.

Return Value:
A new instance of the CompareInfo class that is associated with the specified culture and uses string comparison methods in the specified Assembly.
Exceptions
Exception Type Condition
ArgumentNullException assembly is null.
ArgumentException assembly is of an invalid type.
Remarks
The assembly parameter must be of the same type as Module.Assembly.
See also:
Module.Assembly

Return to top


Overloaded Method: GetCompareInfo(
   string name,
   Assembly assembly
)
Summary
Initializes a new instance of the CompareInfo class that is associated with the culture having the specified name and uses string comparison methods in the specified Assembly.
C# Syntax:
public static CompareInfo GetCompareInfo(
   string name,
   Assembly assembly
);
Parameters:

name

A string representing the culture name.

assembly

An Assembly that contains the string comparison methods to use.

Return Value:
A new instance of the CompareInfo class that is associated with the culture having the specified name and uses string comparison methods in the specified Assembly.
Exceptions
Exception Type Condition
ArgumentNullException name is null.

-or-

assembly is null.

ArgumentException name is an invalid culture name.

-or-

assembly is of an invalid type.

Remarks
The assembly parameter must be of the same type as Module.Assembly.
See also:
Module.Assembly

Return to top


Overridden Method: GetHashCode()
Summary
Serves as a hash function for the current CompareInfo for use in hashing algorithms and data structures, such as a hash table.
C# Syntax:
public override int GetHashCode();
Return Value:
A hash code for the current CompareInfo.
Remarks
This method overrides Object.GetHashCode.

This method generates the same hash code for two objects that are equal according to the CompareInfo.Equals method.

See also:
Object.GetHashCode | Hashtable | CompareInfo.Equals

Return to top


Overloaded Method: GetSortKey(
   string source
)
Summary
Gets the SortKey of the specified string.
C# Syntax:
public virtual SortKey GetSortKey(
   string source
);
Parameters:

source

The string for which to get the SortKey.

Return Value:
The SortKey of the specified string.
Remarks
Each character in a string is given several categories of sort weights, including script, alphabetic, case, and diacritic weights. A sort key serves as the repository of these weights for a particular string. For example, a sort key might contain a string of alphabetic weights, followed by a string of case weights, and so on. SortKey is equivalent to the Windows API method LCMapString with the LCMAP_SORTKEY flag.
See also:
SortKey

Return to top


Overloaded Method: GetSortKey(
   string source,
   CompareOptions options
)
Summary
Gets the SortKey of the specified string using the specified CompareOptions value.
C# Syntax:
public virtual SortKey GetSortKey(
   string source,
   CompareOptions options
);
Parameters:

source

The string for which to get the SortKey.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
The SortKey of the specified string using the specified CompareOptions value.
Exceptions
Exception Type Condition
ArgumentException options is not a valid CompareOptions value.
Remarks
Each character in a string is given several categories of sort weights, including script, alphabetic, case, and diacritic weights. A sort key serves as the repository of these weights for a particular string. For example, a sort key might contain a string of alphabetic weights, followed by a string of case weights, and so on. SortKey is equivalent to the Windows API method LCMapString with the LCMAP_SORTKEY flag.
See also:
SortKey | CompareOptions

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


Overloaded Method: IndexOf(
   string source,
   char value
)
Summary
Searches for the specified character and returns the zero-based index of the first occurrence within the entire source string.
C# Syntax:
public virtual int IndexOf(
   string source,
   char value
);
Parameters:

source

The string to search.

value

The character to locate within source.

Return Value:
The zero-based index of the first occurrence of value within the entire source, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.
Remarks
The source string is searched forward starting at the beginning of the string and ending at the end of the string.

This overload performs a culture-sensitive search; that is, if the char is a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), it might be considered equivalent to any occurrence of its components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. To perform an ordinal (culture-insensitive) search, where a char is considered equivalent to another char only if the Unicode values are the same, use one of the overloads that accepts a CompareOptions value as a parameter and use the CompareOptions.Ordinal value. Overloads of String.IndexOf that search for a char perform an ordinal search, while those that search for a string perform a culture-sensitive search.

See also:
CompareInfo.LastIndexOf

Return to top


Overloaded Method: IndexOf(
   string source,
   string value
)
Summary
Searches for the specified substring and returns the zero-based index of the first occurrence within the entire source string.
C# Syntax:
public virtual int IndexOf(
   string source,
   string value
);
Parameters:

source

The string to search.

value

The string to locate within source.

Return Value:
The zero-based index of the first occurrence of value within the entire source, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

value is null.

Remarks
The source string is searched forward starting at the beginning of the string and ending at the end of the string.

This overload performs a culture-sensitive search; that is, 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. To perform an ordinal (culture-insensitive) search, where the Unicode values are compared, use one of the overloads that accepts a CompareOptions value as a parameter and use the CompareOptions.Ordinal value.

See also:
CompareInfo.LastIndexOf

Return to top


Overloaded Method: IndexOf(
   string source,
   char value,
   CompareOptions options
)
Summary
Searches for the specified character and returns the zero-based index of the first occurrence within the entire source string using the specified CompareOptions value.
C# Syntax:
public virtual int IndexOf(
   string source,
   char value,
   CompareOptions options
);
Parameters:

source

The string to search.

value

The character to locate within source.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
The zero-based index of the first occurrence of value within the entire source using the specified CompareOptions value, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.
ArgumentException options is not a valid CompareOptions value.
Remarks
The source string is searched forward starting at the beginning of the string and ending at the end of the string.

The CompareOptions.StringSort value is not valid for this method.

If options does not include the CompareOptions.Ordinal value, this overload performs a culture-sensitive search; that is, if the char is a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), it might be considered equivalent to any occurrence of its components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. If options includes the CompareOptions.Ordinal value, this overload performs an ordinal (culture-insensitive) search; that is, a char is considered equivalent to another char only if the Unicode values are the same. Overloads of String.IndexOf that search for a char perform an ordinal search, while those that search for a string perform a culture-sensitive search.

See also:
CompareInfo.LastIndexOf | CompareOptions

Return to top


Overloaded Method: IndexOf(
   string source,
   char value,
   int startIndex
)
Summary
Searches for the specified character and returns the zero-based index of the first occurrence within the section of the source string that extends from the specified index to the end of the string.
C# Syntax:
public virtual int IndexOf(
   string source,
   char value,
   int startIndex
);
Parameters:

source

The string to search.

value

The character to locate within source.

startIndex

The zero-based starting index of the search.

Return Value:
The zero-based index of the first occurrence of value within the section of source that extends from startIndex to the end of source, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.
ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.
Remarks
The source string is searched forward starting at startIndex and ending at the end of the string.

This overload performs a culture-sensitive search; that is, if the char is a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), it might be considered equivalent to any occurrence of its components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. To perform an ordinal (culture-insensitive) search, where a char is considered equivalent to another char only if the Unicode values are the same, use one of the overloads that accepts a CompareOptions value as a parameter and use the CompareOptions.Ordinal value. Overloads of String.IndexOf that search for a char perform an ordinal search, while those that search for a string perform a culture-sensitive search.

See also:
CompareInfo.LastIndexOf

Return to top


Overloaded Method: IndexOf(
   string source,
   string value,
   CompareOptions options
)
Summary
Searches for the specified substring and returns the zero-based index of the first occurrence within the entire source string using the specified CompareOptions value.
C# Syntax:
public virtual int IndexOf(
   string source,
   string value,
   CompareOptions options
);
Parameters:

source

The string to search.

value

The string to locate within source.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
The zero-based index of the first occurrence of value within the entire source using the specified CompareOptions value, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

value is null.

ArgumentException options is not a valid CompareOptions value.
Remarks
The source string is searched forward starting at the beginning of the string and ending at the end of the string.

The CompareOptions.StringSort value is not valid for this method.

If options does not include the CompareOptions.Ordinal value, this overload performs a culture-sensitive search; that is, 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. If options includes the CompareOptions.Ordinal value, this overload performs an ordinal (culture-insensitive) search, where the Unicode values are compared.

See also:
CompareInfo.LastIndexOf | CompareOptions

Return to top


Overloaded Method: IndexOf(
   string source,
   string value,
   int startIndex
)
Summary
Searches for the specified substring and returns the zero-based index of the first occurrence within the section of the source string that extends from the specified index to the end of the string.
C# Syntax:
public virtual int IndexOf(
   string source,
   string value,
   int startIndex
);
Parameters:

source

The string to search.

value

The string to locate within source.

startIndex

The zero-based starting index of the search.

Return Value:
The zero-based index of the first occurrence of value within the section of source that extends from startIndex to the end of source, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

value is null.

ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.
Remarks
The source string is searched forward starting at startIndex and ending at the end of the string.

This overload performs a culture-sensitive search; that is, 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. To perform an ordinal (culture-insensitive) search, where the Unicode values are compared, use one of the overloads that accepts a CompareOptions value as a parameter and use the CompareOptions.Ordinal value.

See also:
CompareInfo.LastIndexOf

Return to top


Overloaded Method: IndexOf(
   string source,
   char value,
   int startIndex,
   CompareOptions options
)
Summary
Searches for the specified character and returns the zero-based index of the first occurrence within the section of the source string that extends from the specified index to the end of the string using the specified CompareOptions value.
C# Syntax:
public virtual int IndexOf(
   string source,
   char value,
   int startIndex,
   CompareOptions options
);
Parameters:

source

The string to search.

value

The character to locate within source.

startIndex

The zero-based starting index of the search.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
The zero-based index of the first occurrence of value within the section of source that extends from startIndex to the end of source using the specified CompareOptions value, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.
ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.
ArgumentException options is not a valid CompareOptions value.
Remarks
The source string is searched forward starting at startIndex and ending at the end of the string.

The CompareOptions.StringSort value is not valid for this method.

If options does not include the CompareOptions.Ordinal value, this overload performs a culture-sensitive search; that is, if the char is a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), it might be considered equivalent to any occurrence of its components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. If options includes the CompareOptions.Ordinal value, this overload performs an ordinal (culture-insensitive) search; that is, a char is considered equivalent to another char only if the Unicode values are the same. Overloads of String.IndexOf that search for a char perform an ordinal search, while those that search for a string perform a culture-sensitive search.

See also:
CompareInfo.LastIndexOf | CompareOptions

Return to top


Overloaded Method: IndexOf(
   string source,
   char value,
   int startIndex,
   int count
)
Summary
Searches for the specified character and returns the zero-based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements.
C# Syntax:
public virtual int IndexOf(
   string source,
   char value,
   int startIndex,
   int count
);
Parameters:

source

The string to search.

value

The character to locate within source.

startIndex

The zero-based starting index of the search.

count

The number of elements in the section to search.

Return Value:
The zero-based index of the first occurrence of value within the section of source that starts at startIndex and contains the number of elements specified by count, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.
ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.

-or-

count is less than zero.

-or-

startIndex and count do not specify a valid section in source.

Remarks
The source string is searched forward starting at startIndex and ending at startIndex + count - 1.

This overload performs a culture-sensitive search; that is, if the char is a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), it might be considered equivalent to any occurrence of its components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. To perform an ordinal (culture-insensitive) search, where a char is considered equivalent to another char only if the Unicode values are the same, use one of the overloads that accepts a CompareOptions value as a parameter and use the CompareOptions.Ordinal value. Overloads of String.IndexOf that search for a char perform an ordinal search, while those that search for a string perform a culture-sensitive search.

See also:
CompareInfo.LastIndexOf

Return to top


Overloaded Method: IndexOf(
   string source,
   string value,
   int startIndex,
   CompareOptions options
)
Summary
Searches for the specified substring and returns the zero-based index of the first occurrence within the section of the source string that extends from the specified index to the end of the string using the specified CompareOptions value.
C# Syntax:
public virtual int IndexOf(
   string source,
   string value,
   int startIndex,
   CompareOptions options
);
Parameters:

source

The string to search.

value

The string to locate within source.

startIndex

The zero-based starting index of the search.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
The zero-based index of the first occurrence of value within the section of source that extends from startIndex to the end of source using the specified CompareOptions value, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

value is null.

ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.
ArgumentException options is not a valid CompareOptions value.
Remarks
The source string is searched forward starting at startIndex and ending at the end of the string.

The CompareOptions.StringSort value is not valid for this method.

If options does not include the CompareOptions.Ordinal value, this overload performs a culture-sensitive search; that is, 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. If options includes the CompareOptions.Ordinal value, this overload performs an ordinal (culture-insensitive) search, where the Unicode values are compared.

See also:
CompareInfo.LastIndexOf | CompareOptions

Return to top


Overloaded Method: IndexOf(
   string source,
   string value,
   int startIndex,
   int count
)
Summary
Searches for the specified substring and returns the zero-based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements.
C# Syntax:
public virtual int IndexOf(
   string source,
   string value,
   int startIndex,
   int count
);
Parameters:

source

The string to search.

value

The string to locate within source.

startIndex

The zero-based starting index of the search.

count

The number of elements in the section to search.

Return Value:
The zero-based index of the first occurrence of value within the section of source that starts at startIndex and contains the number of elements specified by count, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

value is null.

ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.

-or-

count is less than zero.

-or-

startIndex and count do not specify a valid section in source.

Remarks
The source string is searched forward starting at startIndex and ending at startIndex + count - 1.

This overload performs a culture-sensitive search; that is, 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. To perform an ordinal (culture-insensitive) search, where the Unicode values are compared, use one of the overloads that accepts a CompareOptions value as a parameter and use the CompareOptions.Ordinal value.

See also:
CompareInfo.LastIndexOf

Return to top


Overloaded Method: IndexOf(
   string source,
   char value,
   int startIndex,
   int count,
   CompareOptions options
)
Summary
Searches for the specified character and returns the zero-based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements using the specified CompareOptions value.
C# Syntax:
public virtual int IndexOf(
   string source,
   char value,
   int startIndex,
   int count,
   CompareOptions options
);
Parameters:

source

The string to search.

value

The character to locate within source.

startIndex

The zero-based starting index of the search.

count

The number of elements in the section to search.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
The zero-based index of the first occurrence of value within the section of source that starts at startIndex and contains the number of elements specified by count, using the specified CompareOptions value, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.
ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.

-or-

count is less than zero.

-or-

startIndex and count do not specify a valid section in source.

ArgumentException options is not a valid CompareOptions value.
Remarks
The source string is searched forward starting at startIndex and ending at startIndex + count - 1.

The CompareOptions.StringSort value is not valid for this method.

If options does not include the CompareOptions.Ordinal value, this overload performs a culture-sensitive search; that is, if the char is a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), it might be considered equivalent to any occurrence of its components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. If options includes the CompareOptions.Ordinal value, this overload performs an ordinal (culture-insensitive) search; that is, a char is considered equivalent to another char only if the Unicode values are the same. Overloads of String.IndexOf that search for a char perform an ordinal search, while those that search for a string perform a culture-sensitive search.

See also:
CompareInfo.LastIndexOf | CompareOptions

Return to top


Overloaded Method: IndexOf(
   string source,
   string value,
   int startIndex,
   int count,
   CompareOptions options
)
Summary
Searches for the specified substring and returns the zero-based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements using the specified CompareOptions value.
C# Syntax:
public virtual int IndexOf(
   string source,
   string value,
   int startIndex,
   int count,
   CompareOptions options
);
Parameters:

source

The string to search.

value

The string to locate within source.

startIndex

The zero-based starting index of the search.

count

The number of elements in the section to search.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
The zero-based index of the first occurrence of value within the section of source that starts at startIndex and contains the number of elements specified by count, using the specified CompareOptions value, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

value is null.

ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.

-or-

count is less than zero.

-or-

startIndex and count do not specify a valid section in source.

ArgumentException options is not a valid CompareOptions value.
Remarks
The source string is searched forward starting at startIndex and ending at startIndex + count - 1.

The CompareOptions.StringSort value is not valid for this method.

If options does not include the CompareOptions.Ordinal value, this overload performs a culture-sensitive search; that is, 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. If options includes the CompareOptions.Ordinal value, this overload performs an ordinal (culture-insensitive) search, where the Unicode values are compared.

See also:
CompareInfo.LastIndexOf | CompareOptions

Return to top


Overloaded Method: IsPrefix(
   string source,
   string prefix
)
Summary
Determines whether the specified source string starts with the specified prefix.
C# Syntax:
public virtual bool IsPrefix(
   string source,
   string prefix
);
Parameters:

source

The string to search in.

prefix

The string to compare with the beginning of source.

Return Value:
true if the length of prefix is less than or equal to the length of source and source starts with prefix; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

prefix is null.

Remarks
Every string starts and ends with an empty substring (""); therefore, if prefix is an empty string, this method returns true.
See also:
CompareInfo.IsSuffix

Return to top


Overloaded Method: IsPrefix(
   string source,
   string prefix,
   CompareOptions options
)
Summary
Determines whether the specified source string starts with the specified prefix using the specified CompareOptions value.
C# Syntax:
public virtual bool IsPrefix(
   string source,
   string prefix,
   CompareOptions options
);
Parameters:

source

The string to search in.

prefix

The string to compare with the beginning of source.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
true if the length of prefix is less than or equal to the length of source and source starts with prefix; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

prefix is null.

ArgumentException options is not a valid CompareOptions value.
Remarks
Every string starts and ends with an empty substring (""); therefore, if prefix is an empty string, this method returns true.

The CompareOptions.StringSort value is not valid for this method.

See also:
CompareInfo.IsSuffix | CompareOptions

Return to top


Overloaded Method: IsSuffix(
   string source,
   string suffix
)
Summary
Determines whether the specified source string ends with the specified suffix.
C# Syntax:
public virtual bool IsSuffix(
   string source,
   string suffix
);
Parameters:

source

The string to search in.

suffix

The string to compare with the end of source.

Return Value:
true if the length of suffix is less than or equal to the length of source and source ends with suffix; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

suffix is null.

Remarks
Every string starts and ends with an empty substring (""); therefore, if suffix is an empty string, this method returns true.
See also:
CompareInfo.IsPrefix

Return to top


Overloaded Method: IsSuffix(
   string source,
   string suffix,
   CompareOptions options
)
Summary
Determines whether the specified source string ends with the specified suffix using the specified CompareOptions value.
C# Syntax:
public virtual bool IsSuffix(
   string source,
   string suffix,
   CompareOptions options
);
Parameters:

source

The string to search in.

suffix

The string to compare with the end of source.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
true if the length of suffix is less than or equal to the length of source and source ends with suffix; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

suffix is null.

ArgumentException options is not a valid CompareOptions value.
Remarks
Every string starts and ends with an empty substring (""); therefore, if suffix is an empty string, this method returns true.

The CompareOptions.StringSort value is not valid for this method.

See also:
CompareInfo.IsPrefix | CompareOptions

Return to top


Overloaded Method: LastIndexOf(
   string source,
   char value
)
Summary
Searches for the specified character and returns the zero-based index of the last occurrence within the entire source string.
C# Syntax:
public virtual int LastIndexOf(
   string source,
   char value
);
Parameters:

source

The string to search.

value

The character to locate within source.

Return Value:
The zero-based index of the last occurrence of value within the entire source, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.
Remarks
The source string is searched backward starting at the end of the string and ending at the beginning of the string.

This overload performs a culture-sensitive search; that is, if the char is a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), it might be considered equivalent to any occurrence of its components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. To perform an ordinal (culture-insensitive) search, where a char is considered equivalent to another char only if the Unicode values are the same, use one of the overloads that accepts a CompareOptions value as a parameter and use the CompareOptions.Ordinal value. Overloads of String.LastIndexOf that search for a char perform an ordinal search, while those that search for a string perform a culture-sensitive search.

See also:
CompareInfo.IndexOf

Return to top


Overloaded Method: LastIndexOf(
   string source,
   string value
)
Summary
Searches for the specified substring and returns the zero-based index of the last occurrence within the entire source string.
C# Syntax:
public virtual int LastIndexOf(
   string source,
   string value
);
Parameters:

source

The string to search.

value

The string to locate within source.

Return Value:
The zero-based index of the last occurrence of value within the entire source, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

value is null.

Remarks
The source string is searched backward starting at the end of the string and ending at the beginning of the string.

This overload performs a culture-sensitive search; that is, 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. To perform an ordinal (culture-insensitive) search, where the Unicode values are compared, use one of the overloads that accepts a CompareOptions value as a parameter and use the CompareOptions.Ordinal value.

See also:
CompareInfo.IndexOf

Return to top


Overloaded Method: LastIndexOf(
   string source,
   char value,
   CompareOptions options
)
Summary
Searches for the specified character and returns the zero-based index of the last occurrence within the entire source string using the specified CompareOptions value.
C# Syntax:
public virtual int LastIndexOf(
   string source,
   char value,
   CompareOptions options
);
Parameters:

source

The string to search.

value

The character to locate within source.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
The zero-based index of the last occurrence of value within the entire source using the specified CompareOptions value, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.
ArgumentException options is not a valid CompareOptions value.
Remarks
The source string is searched backward starting at the end of the string and ending at the beginning of the string.

The CompareOptions.StringSort value is not valid for this method.

If options does not include the CompareOptions.Ordinal value, this overload performs a culture-sensitive search; that is, if the char is a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), it might be considered equivalent to any occurrence of its components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. If options includes the CompareOptions.Ordinal value, this overload performs an ordinal (culture-insensitive) search; that is, a char is considered equivalent to another char only if the Unicode values are the same. Overloads of String.LastIndexOf that search for a char perform an ordinal search, while those that search for a string perform a culture-sensitive search.

See also:
CompareInfo.IndexOf | CompareOptions

Return to top


Overloaded Method: LastIndexOf(
   string source,
   char value,
   int startIndex
)
Summary
Searches for the specified character and returns the zero-based index of the last occurrence within the section of the source string that extends from the beginning of the string to the specified index.
C# Syntax:
public virtual int LastIndexOf(
   string source,
   char value,
   int startIndex
);
Parameters:

source

The string to search.

value

The character to locate within source.

startIndex

The zero-based starting index of the backward search.

Return Value:
The zero-based index of the last occurrence of value within the section of source that extends from the beginning of source to startIndex, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.
ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.
Remarks
The source string is searched backward starting at startIndex and ending at the beginning of the string.

This overload performs a culture-sensitive search; that is, if the char is a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), it might be considered equivalent to any occurrence of its components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. To perform an ordinal (culture-insensitive) search, where a char is considered equivalent to another char only if the Unicode values are the same, use one of the overloads that accepts a CompareOptions value as a parameter and use the CompareOptions.Ordinal value. Overloads of String.LastIndexOf that search for a char perform an ordinal search, while those that search for a string perform a culture-sensitive search.

See also:
CompareInfo.IndexOf

Return to top


Overloaded Method: LastIndexOf(
   string source,
   string value,
   CompareOptions options
)
Summary
Searches for the specified substring and returns the zero-based index of the last occurrence within the entire source string using the specified CompareOptions value.
C# Syntax:
public virtual int LastIndexOf(
   string source,
   string value,
   CompareOptions options
);
Parameters:

source

The string to search.

value

The string to locate within source.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
The zero-based index of the last occurrence of value within the entire source using the specified CompareOptions value, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

value is null.

ArgumentException options is not a valid CompareOptions value.
Remarks
The source string is searched backward starting at the end of the string and ending at the beginning of the string.

The CompareOptions.StringSort value is not valid for this method.

If options does not include the CompareOptions.Ordinal value, this overload performs a culture-sensitive search; that is, 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. If options includes the CompareOptions.Ordinal value, this overload performs an ordinal (culture-insensitive) search, where the Unicode values are compared.

See also:
CompareInfo.IndexOf | CompareOptions

Return to top


Overloaded Method: LastIndexOf(
   string source,
   string value,
   int startIndex
)
Summary
Searches for the specified substring and returns the zero-based index of the last occurrence within the section of the source string that extends from the beginning of the string to the specified index.
C# Syntax:
public virtual int LastIndexOf(
   string source,
   string value,
   int startIndex
);
Parameters:

source

The string to search.

value

The string to locate within source.

startIndex

The zero-based starting index of the backward search.

Return Value:
The zero-based index of the last occurrence of value within the section of source that extends from the beginning of source to startIndex, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

value is null.

ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.
Remarks
The source string is searched backward starting at startIndex and ending at the beginning of the string.

This overload performs a culture-sensitive search; that is, 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. To perform an ordinal (culture-insensitive) search, where the Unicode values are compared, use one of the overloads that accepts a CompareOptions value as a parameter and use the CompareOptions.Ordinal value.

See also:
CompareInfo.IndexOf

Return to top


Overloaded Method: LastIndexOf(
   string source,
   char value,
   int startIndex,
   CompareOptions options
)
Summary
Searches for the specified character and returns the zero-based index of the last occurrence within the section of the source string that extends from the beginning of the string to the specified index using the specified CompareOptions value.
C# Syntax:
public virtual int LastIndexOf(
   string source,
   char value,
   int startIndex,
   CompareOptions options
);
Parameters:

source

The string to search.

value

The character to locate within source.

startIndex

The zero-based starting index of the backward search.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
The zero-based index of the last occurrence of value within the section of source that extends from the beginning of source to startIndex using the specified CompareOptions value, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.
ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.
ArgumentException options is not a valid CompareOptions value.
Remarks
The source string is searched backward starting at startIndex and ending at the beginning of the string.

The CompareOptions.StringSort value is not valid for this method.

If options does not include the CompareOptions.Ordinal value, this overload performs a culture-sensitive search; that is, if the char is a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), it might be considered equivalent to any occurrence of its components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. If options includes the CompareOptions.Ordinal value, this overload performs an ordinal (culture-insensitive) search; that is, a char is considered equivalent to another char only if the Unicode values are the same. Overloads of String.LastIndexOf that search for a char perform an ordinal search, while those that search for a string perform a culture-sensitive search.

See also:
CompareInfo.IndexOf | CompareOptions

Return to top


Overloaded Method: LastIndexOf(
   string source,
   char value,
   int startIndex,
   int count
)
Summary
Searches for the specified character and returns the zero-based index of the last occurrence within the section of the source string that contains the specified number of elements and ends at the specified index.
C# Syntax:
public virtual int LastIndexOf(
   string source,
   char value,
   int startIndex,
   int count
);
Parameters:

source

The string to search.

value

The character to locate within source.

startIndex

The zero-based starting index of the backward search.

count

The number of elements in the section to search.

Return Value:
The zero-based index of the last occurrence of value within the section of source that contains the number of elements specified by count and ends at startIndex, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.
ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.

-or-

count is less than zero.

-or-

startIndex and count do not specify a valid section in source.

Remarks
The source string is searched backward starting at startIndex and ending at startIndex - count + 1.

This overload performs a culture-sensitive search; that is, if the char is a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), it might be considered equivalent to any occurrence of its components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. To perform an ordinal (culture-insensitive) search, where a char is considered equivalent to another char only if the Unicode values are the same, use one of the overloads that accepts a CompareOptions value as a parameter and use the CompareOptions.Ordinal value. Overloads of String.LastIndexOf that search for a char perform an ordinal search, while those that search for a string perform a culture-sensitive search.

See also:
CompareInfo.IndexOf

Return to top


Overloaded Method: LastIndexOf(
   string source,
   string value,
   int startIndex,
   CompareOptions options
)
Summary
Searches for the specified substring and returns the zero-based index of the last occurrence within the section of the source string that extends from the beginning of the string to the specified index using the specified CompareOptions value.
C# Syntax:
public virtual int LastIndexOf(
   string source,
   string value,
   int startIndex,
   CompareOptions options
);
Parameters:

source

The string to search.

value

The string to locate within source.

startIndex

The zero-based starting index of the backward search.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
The zero-based index of the last occurrence of value within the section of source that extends from the beginning of source to startIndex using the specified CompareOptions value, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

value is null.

ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.
ArgumentException options is not a valid CompareOptions value.
Remarks
The source string is searched backward starting at startIndex and ending at the beginning of the string.

The CompareOptions.StringSort value is not valid for this method.

If options does not include the CompareOptions.Ordinal value, this overload performs a culture-sensitive search; that is, 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. If options includes the CompareOptions.Ordinal value, this overload performs an ordinal (culture-insensitive) search, where the Unicode values are compared.

See also:
CompareInfo.IndexOf | CompareOptions

Return to top


Overloaded Method: LastIndexOf(
   string source,
   string value,
   int startIndex,
   int count
)
Summary
Searches for the specified substring and returns the zero-based index of the last occurrence within the section of the source string that contains the specified number of elements and ends at the specified index.
C# Syntax:
public virtual int LastIndexOf(
   string source,
   string value,
   int startIndex,
   int count
);
Parameters:

source

The string to search.

value

The string to locate within source.

startIndex

The zero-based starting index of the backward search.

count

The number of elements in the section to search.

Return Value:
The zero-based index of the last occurrence of value within the section of source that contains the number of elements specified by count and ends at startIndex, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

value is null.

ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.

-or-

count is less than zero.

-or-

startIndex and count do not specify a valid section in source.

Remarks
The source string is searched backward starting at startIndex and ending at startIndex - count + 1.

This overload performs a culture-sensitive search; that is, 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. To perform an ordinal (culture-insensitive) search, where the Unicode values are compared, use one of the overloads that accepts a CompareOptions value as a parameter and use the CompareOptions.Ordinal value.

See also:
CompareInfo.IndexOf

Return to top


Overloaded Method: LastIndexOf(
   string source,
   char value,
   int startIndex,
   int count,
   CompareOptions options
)
Summary
Searches for the specified character and returns the zero-based index of the last occurrence within the section of the source string that contains the specified number of elements and ends at the specified index using the specified CompareOptions value.
C# Syntax:
public virtual int LastIndexOf(
   string source,
   char value,
   int startIndex,
   int count,
   CompareOptions options
);
Parameters:

source

The string to search.

value

The character to locate within source.

startIndex

The zero-based starting index of the backward search.

count

The number of elements in the section to search.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
The zero-based index of the last occurrence of value within the section of source that contains the number of elements specified by count and ends at startIndex using the specified CompareOptions value, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.
ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.

-or-

count is less than zero.

-or-

startIndex and count do not specify a valid section in source.

ArgumentException options is not a valid CompareOptions value.
Remarks
The source string is searched backward starting at startIndex and ending at startIndex - count + 1.

The CompareOptions.StringSort value is not valid for this method.

If options does not include the CompareOptions.Ordinal value, this overload performs a culture-sensitive search; that is, if the char is a Unicode value representing a precomposed character, such as the ligature 'Æ' (U+00C6), it might be considered equivalent to any occurrence of its components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. If options includes the CompareOptions.Ordinal value, this overload performs an ordinal (culture-insensitive) search; that is, a char is considered equivalent to another char only if the Unicode values are the same. Overloads of String.LastIndexOf that search for a char perform an ordinal search, while those that search for a string perform a culture-sensitive search.

See also:
CompareInfo.IndexOf | CompareOptions

Return to top


Overloaded Method: LastIndexOf(
   string source,
   string value,
   int startIndex,
   int count,
   CompareOptions options
)
Summary
Searches for the specified substring and returns the zero-based index of the last occurrence within the section of the source string that contains the specified number of elements and ends at the specified index using the specified CompareOptions value.
C# Syntax:
public virtual int LastIndexOf(
   string source,
   string value,
   int startIndex,
   int count,
   CompareOptions options
);
Parameters:

source

The string to search.

value

The string to locate within source.

startIndex

The zero-based starting index of the backward search.

count

The number of elements in the section to search.

options

The CompareOptions value that defines how the strings should be compared.

Return Value:
The zero-based index of the last occurrence of value within the section of source that contains the number of elements specified by count and ends at startIndex using the specified CompareOptions value, if found; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException source is null.

-or-

value is null.

ArgumentOutOfRangeException startIndex is outside the range of valid indexes for source.

-or-

count is less than zero.

-or-

startIndex and count do not specify a valid section in source.

ArgumentException options is not a valid CompareOptions value.
Remarks
The source string is searched backward starting at startIndex and ending at startIndex - count + 1.

The CompareOptions.StringSort value is not valid for this method.

If options does not include the CompareOptions.Ordinal value, this overload performs a culture-sensitive search; that is, 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. If options includes the CompareOptions.Ordinal value, this overload performs an ordinal (culture-insensitive) search, where the Unicode values are compared.

See also:
CompareInfo.IndexOf | CompareOptions

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


Overridden Method: ToString()
Summary
Returns a string that represents the current CompareInfo.
C# Syntax:
public override string ToString();
Return Value:
A string that represents the current CompareInfo.
Remarks
This method overrides Object.ToString.
See also:
Object.ToString | String

Return to top


Top of page

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