Instr
instr
searches for a given substring in a string, starting at a given position.
instr(EXPR_POSITION,EXPR_STRING,EXPR_SUBSTRING)
EXPR_POSITION
is a positive integer expression that defines the first position to search in the string.EXPR_STRING
is a string expression in which the substring is searched.EXPR_SUBSTRING
is a string expression that defines the string to be searched. # 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
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.
Error code | Description |
---|---|
10 | The position argument is not numeric. The string or substring parameter is not a string or a CLOB. |
50 | The position is negative |
left$, right$, string$, space$, mid$, vireblc.