lastIndexOf

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

Returns the index within this string of the rightmost occurrence of the specified substring. The rightmost empty string "" is considered to occur at the index value this.length(). The returned index is the largest value k such that


this.toString().startsWith(str, k)
is true.

Return

if the string argument occurs one or more times as a substring within this object, then the index of the first character of the last such substring is returned. If it does not occur as a substring, -1 is returned.

Parameters

str

the substring to search for.


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

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


    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 sequence of the last occurrence of the specified substring.

Parameters

str

the substring to search for.

fromIndex

the index to start the search from.