C#StringIndexOf

Returns the zero-based index of the first occurrence of a value.

Syntax

str.IndexOf(value, startIndex?)

Example

Enter values below to update the example in real time.

string
idx
IndexOf
Console
WriteLine
string text = "Hello World Hello";
int idx = text.IndexOf("Hello");
Console.WriteLine(idx);   // 0