Finds the position (or positions) of a given sub-string within a string.
LOCATE | astring=String substring=String [count=Integer] | Returns the index position of a sub-string within the string |
example:
# Look for all the positions of the string "quick" >> position = 0 >> words = "The quick brown quick fox& jumped quick over the lazy quick dog" LOOP i FROM 1 TO 10 position = locate(words,"quick",i) EXITIF position = 0 print position ENDLOOP 5 17 33 53>>
Note: Locate() is most useful when used in conjunction with the Substring() function.
Locate allows the position of a substring to be found within a string. If necessary, it is possible to specify an extra count parameter to locate which will allow the position of the nth occurrence of a string to be found. In all cases, if a sub-string is not found, a zero is returned.
Astring (String)
The string which is to be searched for sub-strings.
Substring (String)
The sub-string to search for within the string
count (Integer) [ default=1 ]
Optional parameter to allow the position of the nth substring to be found. This parameter defaults to 1 to look for the first occurrence of the substring.
RESULT = (Integer)
The position of the sub-string within the searched string. The character positions are numbered from 1 for the first character in the string, the same way as for the Substring() command.