C# String IndexOf(String, Int32)
Description
String IndexOf(String, 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.
Syntax
String.IndexOf(String, Int32)
has the following syntax.
public int IndexOf(
string value,
int startIndex
)
Parameters
String.IndexOf(String, Int32)
has the following parameters.
value
- The string to seek.startIndex
- The search starting position.
Returns
String.IndexOf(String, 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
using System;//www . j a va2s . c om
public class Example
{
public static void Main()
{
string searchString = "\u00ADm";
string s1 = "ani\u00ADmal" ;
string s2 = "animal";
Console.WriteLine(s1.IndexOf(searchString, 2));
Console.WriteLine(s2.IndexOf(searchString, 2));
}
}
The code above generates the following result.