Name

indexof — Return the starting position of a substring within a string.

Syntax

indexof(string, substring)
              

The INDEXOF 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 first 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

indexof('foobar', 'bar')

Return the locaton of 'bar' within 'foobar'

3

indexof('foobar', 'foo')

Return the locaton of 'foo' within 'foobar'

0

indexof('foobar', 'baz')

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

-1

indexof('banana', 'na')

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

2