Given a string and we have find the index of a substring.
String.IndexOf() method
It is a method of string class, which returns the first index (first occurrence) of the character in a string.
Syntax:
int String.IndexOf(String str);
This method returns integer value; it returns the index when sub-string found in string. If sub-string is not found in string then it returns negative value.
Example of String.IndexOf() in C#
Output