Instr

instr searches for a given substring in a string, starting at a given position.

Syntax

 instr(EXPR_POSITION,EXPR_STRING,EXPR_SUBSTRING)

Examples

 # Search for GHI substring in a stringLocal Integer II=substring(1,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","GHI") : # I equals 7 now# Count the number of occurrences of the word defined by SEARCH_WORD in a TEXT variable# The result is computed in OCCURRENCES valueFunprog COUNT_WORDS(SEARCH_WORD,TEXT)Value Char SEARCH_WORD()Variable Clbfile TEXT()Local Integer OCCURRENCES,I,KK=len(SEARCH_WORD) : I = 1-K : OCCURRENCES = -1Repeat I = instr(I+K, TEXT, SEARCH_WORD) : OCCURRENCES += 1 : Until I = 0End OCCURRENCES

Description

instr searches a substring in a string or a CLOB from an initial position and returns the position (in number of characters) of the first occurrence found. If the substring is not found, instr returns 0.

The type of the result is Integer.

Associated errors

Error codeDescription
10The position argument is not numeric.
The string or substring parameter is not a string or a CLOB.
50The position is negative

See also

left$, right$, string$, space$, mid$, vireblc.