Skip to main content
.NET Framework Class Library
String..::.IndexOf Method





Reports the zero-based index of the first occurrence of one or more characters, or the first occurrence of a string, within this string. The method returns -1 if the character or string is not found in this instance.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

Overload List
 NameDescription
Public methodIndexOf(Char)Reports the zero-based index of the first occurrence of the specified Unicode character in this string.
Public methodIndexOf(String)Reports the zero-based index of the first occurrence of the specified string in this instance.
Public methodIndexOf(Char, Int32)Reports the zero-based index of the first occurrence of the specified Unicode character in this string. The search starts at a specified character position.
Public methodIndexOf(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.
Public methodIndexOf(String, StringComparison)Reports the zero-based index of the first occurrence of the specified string in the current String object. A parameter specifies the type of search to use for the specified string.
Public methodIndexOf(Char, Int32, Int32)Reports the zero-based index of the first occurrence of the specified character in this instance. The search starts at a specified character position and examines a specified number of character positions.
Public methodIndexOf(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.
Public methodIndexOf(String, Int32, StringComparison)Reports the zero-based index of the first occurrence of the specified string in the current String object. Parameters specify the starting search position in the current string and the type of search to use for the specified string.
Public methodIndexOf(String, Int32, Int32, StringComparison)Reports the zero-based index of the first occurrence of the specified string in the current String object. Parameters specify the starting search position in the current string, the number of characters in the current string to search, and the type of search to use for the specified string.
Top
Microsoft is conducting an online survey to understand your opinion of the MSDN Web site. If you choose to participate, the online survey will be presented to you when you leave the MSDN Web site.

Would you like to participate?