Export (0) Print
Expand All

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.

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

abstract IndexOf : 
        source:string * 
        value:char * 
        startIndex:int -> int 
override IndexOf : 
        source:string * 
        value:char * 
        startIndex:int -> int 

Parameters

source
Type: System.String
The string to search.
value
Type: System.Char
The character to locate within source.
startIndex
Type: System.Int32
The zero-based starting index of the search.

Return Value

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

ExceptionCondition
ArgumentNullException

source is a null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

startIndex is outside the range of valid indexes for source.

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.

NoteNote

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.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Community Additions

ADD
Show:
© 2014 Microsoft