indexOf

open fun indexOf(@NonNull str: String): Int

Returns the index within this string of the first occurrence of the specified substring. The integer returned is the smallest value k such that:


this.toString().startsWith(str, <i>k</i>)
is true.

Return

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.

Parameters

str

any string.


open fun indexOf(@NonNull str: String, fromIndex: Int): Int

Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. The integer returned is the smallest value k for which:


    k >= Math.min(fromIndex, this.length()) &&
                  this.toString().startsWith(str, k)
If no such value of k exists, then -1 is returned.

Return

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

Parameters

str

the substring for which to search.

fromIndex

the index from which to start the search.