Find the first or last occurrence of a character

Syntax

INDEX(…string-expr…, …char-expr…)

INDEX FROM START(…string-expr…, …char-expr…)

INDEX FROM END(…string-expr…, …char-expr…)

Typing

STRING -> CHAR -> BOOL

Description

Returns the position of the first (or last) occurrence of the given character in the given string.

The position of the first character is 0.

Notice that the search is case sensitive.

If the character is not present in the string then -1 is returned

Examples

expression evaluates to
INDEX("foobar", #\o) 1
INDEX("foobar", #\O) -1
INDEX FROM END("foobar", #\o) 2

See Also

String-ends-with operator String-starts-with operator