Returns the index of the first occurrence of a specified Unicode character
in the current instance, with the search starting from a specified index.
[Edit]
Parameters
- value
- A Unicode character.
[Edit]
- startIndex
- A int containing the index of the current instance from which to start searching.
[Edit]
Returns
A int containing the zero-based index of the first occurrence of
value in the current instance starting from the specified index; otherwise, -1 if value was not found.
[Edit]
Exceptions
Remarks
Example
The following example demonstrates the string.IndexOf(char)
method.
C# Example |
using System;
public class StringIndexOf {
public static void Main() {
String str = "This is the string";
Console.WriteLine( "Searching for the index of 'h' starting from index 0 yields {0}.", str.IndexOf( 'h', 0 ) );
Console.WriteLine( "Searching for the index of 'h' starting from index 10 yields {0}.", str.IndexOf( 'h', 10 ) );
}
}
|
The output is
Searching for the index of 'h' starting from index 0 yields 1.
Searching for the index of 'h' starting from index 10 yields -1.
Requirements
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0