Description

Examines a string for the occurrence of a specified substring. Returns the starting position of the designated substring in the string. Index() is case sensitive, meaning that the match must be exact. Use indexc() for a case-insensitive match ("Abc" matches "ABC").

Syntax

position = Index (string, substring, occurrence)

Parameters

The Index function has the following parameters.

ParameterDescription
StringAny legal data, including a null.
SubstringThe substring for which to search in string.
OccurrenceDefines which occurrence of substring to locate (presuming the possible existence of more than one).

The Index function returns a numeric value that is the starting character position of substring within the string expression. In the following example:

FIRST = Index("ABRACADABRA", "CAD", 1)

the variable identifier FIRST is assigned the value of 5 because the first occurrence of the substring "CAD" begins in character position 5 in the string "ABRACADABRA." In this example:

T = Index("XXA1YYA1ZZA1," "A1," 3) T would be assigned the numeric value of 11 because the third occurrence of "A1" begins in character position 11.

If the specified occurrence does not exist, or if the substring is not found, a value of zero is returned.

In the above example, if the last expression had been 4, a 0 (zero) would have resulted because the string A1 does not occur four times. A value of 0 (zero) would have resulted also if the substring "2" had been used because the substring does not exist in the string

See also

indexc()

Example

This statement checks if a variable contains more than one field.

if Index (var, @FM, 1) then
  * there are multiple fields
end

This statement removes the second occurrence of "the" from a string.

POS = Index(VAR, "the",2)
If POS Then VAR [POS, Len("the")] = ""
  • No labels