Determines the position within this string of the first occurrence of the specified string.
[Visual Basic] Overloads Public Function IndexOf( _ ByVal value As String, _ ByVal startIndex As Integer, _ ByVal endIndex As Integer _ ) As Integer [C#] public int IndexOf( string value, int startIndex, int endIndex ); [C++] public: int IndexOf( String* value, int startIndex, int endIndex ); [JScript] public function IndexOf( value : String, startIndex : int, endIndex : int ) : int;
Value | Condition |
---|---|
The position | If the string is found. |
The position search began | If the string is the empty string. |
-1 | If the string is not found. |
Exception Type | Condition |
---|---|
ArgumentNullException | If the string is null . |
ArgumentOutOfRangeException | If the start position is not a valid position of this string. |
ArgumentOutOfRangeException | If end position is less than zero or greater than the length of this string plus one. |
The IndexOf method searches for a specified string from the specified starting position and returns the index. The search begins at the first character of this string (startIndex) and ends at the end of the specified position (endIndex). It is case-sensitive, CultureInfo sensitive, and the default locale is used. This method returns the CurrentCulture information.
The value parameter returns the position from where search commenced if value is the empty string (see Empty).
String Class | String Members | System Namespace | String.IndexOf Overload List | Int32