|Command||basic.index Function/BASIC Program
Applicable release versions: AP, R83
|Category||BASIC Program (486)|
|Description||searches through a given "string.expression" for the occurrence of the character or substring specified by "substring.expression" and if found, returns the numeric position at which the nth occurence of the substring begins. Null strings are skipped.
The "num.expression" defines a particular occurrence to find, (nth occurrence).
If the nth occurence of the specified substring is not found, "0" (zero) is returned.
|Syntax||index(string.expression, substring.expression, num.expression)|
d.position = index("abcdefg","d",1) This returns the value, "4", to the variable "test", since the first occurrence of "d" is found in the fourth position of the string. on index("abcdefg",response,1) goto 10,20,30,40,50,60,70 This example exploits the fact that "index" returns a number indicating the position of the search character. For instance, if "response" is the letter "d", then it will goto statement label 40. loop input ans,1 until ans#'' and index('abc',ans,1) do repeat If "ans" is not null and is either an a, b, c, ab, or bc, the loop is terminated. Notice that the null condition must be tested separately since a null value for "ans" results in a "1" from the "index" function.