StringIndexOf Method (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.
Namespace: SystemAssembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
Syntax public int IndexOf(
string value,
int startIndex,
int count,
StringComparison comparisonType
)
Parameters
- value
- Type: SystemString
The string to seek. - startIndex
- Type: SystemInt32
The search starting position. - count
- Type: SystemInt32
The number of character positions to examine. - comparisonType
- Type: SystemStringComparison
One of the enumeration values that specifies the rules for the search.
Return Value
Type:
Int32The zero-based index position of the
value parameter if that string is found, or -1 if it is not. If
value is
Empty, the return value is
startIndex.
Exceptions Exception | Condition |
---|
ArgumentNullException | value is null. |
ArgumentOutOfRangeException | count or startIndex is negative.-or- startIndex is greater than the length of this instance.-or-count is greater than the length of this instance minus startIndex. |
ArgumentException | comparisonType is not a valid StringComparison value. |
See Also