Share via


String.indexOf

Class Overview | Class Members | This Package | All Packages

Syntax 1

public int indexOf( String str )

Parameters
  • str
    any string.
Returns

if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.

Description

Returns the index within this string of the first occurrence of the specified substring.

Syntax 2

public int indexOf( String str**, int** fromIndex )

Parameters
  • str
    the substring to search for.
  • fromIndex
    the index to start the search from.
Returns

If the string argument occurs as a substring within this object at a starting index no smaller than fromIndex, then the index of the first character of the first such substring is returned. If it does not occur as a substring starting at fromIndex or beyond, -1 is returned.

Description

Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.