C# String IndexOf(String, Int32, Int32)
Description
String IndexOf(String, Int32, Int32)
reports the zero-based
index of the first occurrence of the specified string in this instance. The
search starts at a specified character position and examines a specified
number of character positions.
Syntax
String.IndexOf(String, Int32, Int32)
has the following syntax.
public int IndexOf(
string value,/* www . j a va 2 s .c om*/
int startIndex,
int count
)
Parameters
String.IndexOf(String, Int32, Int32)
has the following parameters.
value
- The string to seek.startIndex
- The search starting position.count
- The number of character positions to examine.
Returns
String.IndexOf(String, Int32, Int32)
method returns The zero-based index position of value if that string is found, or -1 if it
is not. If value is String.Empty, the return value is startIndex.
Example
Sample for String.IndexOf(String, Int32, Int32)
using System;/*from w w w .j a v a 2 s. co m*/
public class Example
{
public static void Main()
{
string searchString = "\u00ADm";
string s1 = "ani\u00ADmal" ;
string s2 = "animal";
Console.WriteLine(s1.IndexOf(searchString, 2, 4));
Console.WriteLine(s2.IndexOf(searchString, 2, 4));
}
}
The code above generates the following result.