System Functions
POS( ) Scan String
   
Format POS( pattern$ { = ...} string$ [ ,step [ ,instance ] ] [ ,ERR=stmtref ] )

Where:

{ = ...} Relationship operator. Define the relationship for the string comparison:
: colon Search for first instance of any character in string$ which is in pattern$
e.g POS("0123456789"
: X$) returns first digit in X$
^ caret Search for first instance of any character in string$ which is not in pattern$
e.g POS("0123456789"
^ X$) returns first non-digit in X$
= equals sign Searches for pattern$ in string$
<> greater/less Search for pattern$ not in string$ (usually pattern$ is a single character)
> greater Search for position where pattern$ is greater string$
< less Search for position where pattern$ is less string$
instance Numeric expression tells ProvideX which occurrence(s) to report when the pattern is found in the string.
pattern String value or expression to scan for.
step Increment value of the intervals. Optional. Numeric expression (defaults to 1).
stmtref Program line number or statement label to which to transfer control.
   
Returns Integer, starting position where relationship is satisfied (0 if none)
   
Description The POS( ) function scans the string$ to determine where a portion of it will satisfy the relationship with the pattern string. The function returns an integer reporting the starting position in string$ where the relationship is satisfied, or 0 (zero) if no position satisfies the relationship.

Use the step value to set the logical increment for the next position to be checked. The default is to move one (1) position at a time. If the value of the increment is negative, then the string is scanned from back to front.

Indicate the instance or occurrence for which you want to obtain the POS( ) value. If this value is omitted, the default is 1 (the first instance found). If the value is 0, the POS( ) function returns the total number of matches found.

   
Examples The following examples illustrate the different uses for the POS( ) function.

Example 1:

Given A$="The quick brown fox":

POS("q"=A$) ! yields 5
POS("z"=A$) ! yields 0

Example 2:

Given A$="The quick brown fox":

POS("q"=A$) ! yields 5
POS("z"=A$) ! yields 0
POS("o"=A$) ! yields 13
POS("o"=A$,-1) ! yields 18 - Scan from end (fox)
POS("o"=A$,1,2) ! yields 18 - Second occurrence (fox)
POS("o"=A$,2) ! yields 13 - Checks every 2nd position
POS("r"<A$) ! yields 6 - "u" is first char. > "r"