CompareInfo.IndexOf Method (String, Char, Int32)
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.
Assembly: mscorlib (in mscorlib.dll)
abstract IndexOf : source:string * value:char * startIndex:int -> int override IndexOf : source:string * value:char * startIndex:int -> int
- Type: System.String
The string to search.
- Type: System.Char
The character to locate within source.
- Type: System.Int32
The zero-based starting index of the search.
Return ValueType: System.Int32
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.
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, the application should use one of the overloads that accepts a CompareOptions value as a parameter and use the Ordinal value. Overloads of String.IndexOf that search for a character perform an ordinal search, while those that search for a string perform a culture-sensitive search.
When possible, the application should use string comparison methods that accept a CompareOptions value to specify the kind of comparison expected. As a general rule, user-facing comparisons are best served by the use of linguistic options (using the current culture), while security comparisons should specify Ordinal or OrdinalIgnoreCase.
The following code example determines the indexes of the first and last occurrences of a character or a substring within a portion of a string. Note that IndexOf and LastIndexOf are searching in different portions of the string, even with the same startIndex parameter.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.