System.String.IndexOf Method

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.

Syntax

public int IndexOf (string value, int startIndex, int count, StringComparison comparisonType)

Parameters

value
The string to seek.
startIndex
The search starting position.
count
The number of character positions to examine.
comparisonType
One of the enumeration values that specifies the rules for the search.

Returns

The zero-based index position of the value parameter if that string is found, or -1 if it is not. If value is string.Empty, the return value is startIndex.

Remarks

Index numbering starts from 0 (zero). The startIndex parameter can range from 0 to the length of the string instance.

The search begins at startIndex and continues to startIndex + count -1. The character at startIndex + count is not included in the search.

The comparisonType parameter specifies to search for the value parameter using the current or invariant culture, using a case-sensitive or case-insensitive search, and using word or ordinal comparison rules.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0