INSTR

Function

INSTR searches for the occurrence of one string in another, and returns with the position of the first match.

Syntax

Y = INSTR ([X]A$,B$) 1<X<255

Example

10 A$ = "BASICS"
20 PRINT INSTR (A$,"S")

This program will print 3, since this is the first occurrence of the letter S.

10 A$ = "SUPER BASICS"
20 B$ = "SI"
30 PRINT INSTR(A$,B$)

This program will print 9 as the first occurrence of SI.

10 A$ = "BASICS"
20 PRINT INSTR(4,A$,"S")

The above program will print 6, since this is the first occurrence of the letter S from the fourth character onwards in the string A$.

Remarks

If B$ does not occur in A$, then 0 is returned. X, which is optional and defaults to 1, is used to start the search at a particular place within a string.

Case is also important, i.e. “s” is not the same as “S”.