index() function
.mdThe index() function searches through a given str.exp for the occurrence of the character or substring specified by substr.exp and if found, returns the numeric position where the nth occurrence of the substring begins. Null strings are skipped.
Syntax
index(str.exp, substr.exp, num.exp)Parameter(s)
| str.exp | String to search. |
| substr.exp | Character or substring to search for in str.exp. |
| num.exp | Specifies the particular occurrence of the character or substring to find (nth occurrence). If not found, 0 is returned. |
Description
Example(s)
This returns the value 4 to the
variable test, because the first occurrence of d is
found in the fourth position of the string.
d.position = index("abcdefg","d",1)
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
goes to statement label 40.
on index("abcdefg",response,1) goto 10,20,30,40,50,60,70
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 because a null value for ans results in a 1 from the index() function.
loop input ans,1 until ans#’’ and index(’abc’,ans,1) do repeat
Find the position of an occurrence
print index("mississippi", "ss", 1) ;* 3
See also
Referenced by
2 topics mention index() function in its description.