System.Globalization.CompareInfo.IndexOf Method

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.

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.

Returns

The zero-based index of the first occurrence of value, if found, within the section of source that extends from startIndex to the end of source; otherwise, -1. Returns startIndex if value is an ignorable character.

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. If the character 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 character is considered equivalent to another character only if the Unicode values are the same, you should call one of the overloads that has a parameter of type System.Globalization.CompareOptions and use the CompareOptions.Ordinal value. Overloads of string.IndexOf(char) that search for a character perform an ordinal search, whereas those that search for a string perform a culture-sensitive search.

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