System.Globalization.CompareInfo.IndexOf Method

Searches for the specified substring and returns the zero-based index of the first occurrence within the entire source string using the specified System.Globalization.CompareOptions value.

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
A value that defines how source and value should be compared. options is either the enumeration value CompareOptions.Ordinal, or a bitwise combination of one or more of the following values: CompareOptions.IgnoreCase, CompareOptions.IgnoreSymbols, CompareOptions.IgnoreNonSpace, CompareOptions.IgnoreWidth, and CompareOptions.IgnoreKanaType.

Returns

The zero-based index of the first occurrence of value, if found, within source, using the specified comparison options; otherwise, -1. Returns 0 (zero) if value is an ignorable character.

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

Note:

When possible, you should call string comparison methods that have a parameter of type System.Globalization.CompareOptions to specify the kind of comparison expected. As a general rule, use linguistic options (using the current culture) for comparing strings displayed in the user interface and specify CompareOptions.Ordinal or CompareOptions.OrdinalIgnoreCase for security comparisons.

Requirements

Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0