StrPos Function

Action

Returns the position of the specified substring.

Syntax

iPos = StrPos (sSubstr, sTarget [, bBackward]))
Variable Description
iPos The returned position. INTEGER.
sSubstr The substring to find. STRING.
sTarget The string to search. STRING.
bBackward Optional. If TRUE, searches backward from the end of sTarget and returns the position of sSubstr relative to the first character position in of sTarget, starting from one. If FALSE (default), searches from the beginning of sTarget and returns the position of sSubstr relative to the first character position in sTarget. BOOLEAN.

Notes

Without the bBackward optional argument, StrPos searches sTarget for the specified substring sSubstr. If found, it returns the character position in sTarget of the first character in sSubstr, starting from one (the first character of sTarget). With the optional argument, StrPos searches for sSubstr starting from the last character in sTarget. It returns the character position relative to the first character in sTarget, starting from one.

If the substring is not found, StrPos returns 0 (zero).

Example

STRING s = "now is the time for all the good men"
//search forward to find first occurrence of "the"
Print (StrPos ("the", s)) // prints: 8
//search backward to find second occurrence of "the"
Print (StrPos ("the", s, TRUE)) // prints: 25
Print (StrPos ("x", s)) // prints: 0