POS( ) |
Scan String |
POS(pattern$ { = ...} string$ [ ,step [ ,instance] ] [ ,ERR=stmtref] )
{ = ...} |
Relationship operator. Define the relationship for the string comparison:
| ||||||||||||||||||
instance |
Numeric expression tells PxPlus 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. |
Integer, starting position where relationship is satisfied (0 if none).
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 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.
The following examples illustrate different uses for the POS( ) function:
Given A$="The quick brown fox":
pos("q"=A$) ! Yields 5
pos("z"=A$) ! Yields 0
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"
pos("o"=A$,1,0) ! Yields 2 - Two occurrences of "o"
Any of the comparison operators (i.e. =, :, ^, < and >) can be used for different evaluations of the number of occurrences found within a string.