FindString
All validation programs
Allows you to determine if String A can be found in String B, and if so, return its starting position.
Format of Parameters
StringA StringB ResultVar (StartPos) (Opt)
Where:
StringA
|
The string (variable or constant) to search. |
StringB
|
The substring (variable or constant) to search for. If StringB is not found in StringA, then the result will be zero. Otherwise, it will be the position in StringA that StringB starts (1-based; i.e. the first character position is 1). |
ResultVar
|
The variable to contain the result. Note that if either StringA or StringB is an empty string, the value of -1 will be returned in ResultVar. |
(StartPos)
|
Optional. A variable or constant that tells FindString where to start its search within StringA. If StartPos is omitted, then the search begins in position 1 (i.e. the first character) of StringA. If StartPos is less than 1 or greater than the length of StringA, then a zero will be returned. If StartPos is not numeric, it will be ignored. |
(Opt)
|
Optional. A variable or constant that modifies aspects of the function. Currently, the only option supported is I, which means Ignore Case. |
Examples (Simple)
The following examples use these assumptions:
-
SetVar INVCONST “Office Box”
-
Current element = “Post office box 1234”
This example causes 0 to be put into VARPOPOS because the exact string wasn’t found.
This example causes 6 to be put into VARPOPOS because, once we ignore the case of the letters, the string is found.
Examples (Complex)
This more complex example shows how to find the second occurrence of a delimiter:
The following examples use this assumption:
-
Current element = “123-ER-456TT”
This rule causes 4 to be put into DELIMPOS1.
This AddVar rule increments DELIMPOS1 to 5.
This rule causes 7 to be put into DELIMPOS2.