MongooseA text-based world full of questionable inventions.

All help topics · Link to this topic

Showing help on 'rindex'

Syntax: index (STR str1, STR str2 [, INT case-matters [, INT skip]]) => INT
rindex (STR str1, STR str2 [, INT case-matters [, INT skip]]) => INT

index -- Returns the index of the first character of the first occurrence of str2 in str1.

rindex -- Returns the index of the first character of the last occurrence of str2 in str1.

These functions will return zero if str2 does not occur in str1 at all.

By default the search for an occurrence of str2 is done while ignoring the upper/lower case distinction. If case-matters is provided and true, then case is treated as significant in all comparisons.

By default the search starts at the beginning (end) of str1. If skip is provided, the search skips the first (last) skip characters and starts at an offset from the beginning (end) of str1. The skip must be a positive integer for index() and a negative integer for rindex(). The default value of skip is 0 (skip no characters).

index("foobar", "o") 2
index("foobar", "o", 0, 0) 2
index("foobar", "o", 0, 2) 1
rindex("foobar", "o") 3
rindex("foobar", "o", 0, 0) 3
rindex("foobar", "o", 0, -4) 2
index("foobar", "x") 0
index("foobar", "oba") 3
index("Foobar", "foo", 1) 0