Name

lastindexof — Return the starting position of a substring within a string, searching from the end forward.

Syntax

lastindexof(string, substring)
              

The LASTINDEXOF function has the following arguments:

string

The string to search for the substring.

substring

The substring to search for.

Description

Return the starting position of the last occurrence a substring within a string.

The positon number is indexed starting at zero.

if the substring does not exist within the string then return -1.

Examples

Formula

Description

Result

lastindexof('foobar', 'bar')

Return the locaton of 'bar' within 'foobar'

3

lastindexof('foobar', 'foo')

Return the locaton of 'foo' within 'foobar'

0

lastindexof('foobar', 'baz')

Return the locaton of 'baz' within 'foobar', but it does not exist

-1

lastindexof('banana', 'na')

Return the first locaton of 'na' within 'banana'

4