Returns the index of the first occurrence of a specified Unicode character in the current instance, with the search starting from a specified index.
- value
- A Unicode character.
- startIndex
- A int containing the index of the current instance from which to start searching.
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.
Type Reason ArgumentOutOfRangeException startIndex is less than zero or greater than the length of the current instance.
This method is case-sensitive.
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.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0