Skip to main content
Previous section   Next section

INDEX

Returns starting position of a substring in a string.

Synopsis

INDEX(string,substring,occurs)

Arguments

string The string to be searched for substring. An expression that resolves to a string or a numeric value.
substring An expression that resolves to a substring to locate within string.
occurs An expression that resolves to a positive integer specifying which occurrence of substring to locate.

Description

The INDEX function returns the starting character position, counting from 1, of substring within string. Matching of substring is case-sensitive. You use the occurs argument to specify which occurrence of substring to return the location of.

INDEX returns 0 for any of the following:

  • If substring does not occur in string.

  • If occurs specifies more occurrences of substring than appear in string.

  • If occurs is 0, a negative number, the null string, or a non-numeric string.

  • If string is the null string ("") and substring is not.

If substring is the null string (""), INDEX returns 1. If both string and substring are the null string (""), INDEX returns 1.

If occurs is a mixed numeric string, the numeric part is parsed until a non-numeric character is encountered. Thus “7dwarves” is parsed as 7.

See Also