<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > !STR.- String Command > String Operations |
MiniRobotLanguage (MRL)
STR. FIND - Mode
Find a Text/String inside of a Text/String
Intention
FIND - Mode: Search for a String inside a String. The Result will be placed on TOS.
The Source-String is NOT changed in this Mode.
The result is 0 if the find-string is not found.
The result will be a number between zero and the length of the source-string if the find-string is found in the source string. Here is an example:
VAR.$$SRC=12345AB6789
VAR.$$FND=AB
STR.FIND|$$SRC|1|$$FND
VAR.$$POS=$tos$
DBP.Found at: $$POS
ENR.
We get the expected result:
FIND will always return the first occurrence after the given starting position or zero if nothing was found. If the starting position is zero, starting position 1 is used.
if the starting position is negative, for example -1, special rules apply.
• -1 - start search at the end of the string
• -2 - start search at the second byte from the end of the string
• and so on. Note that in any case, the result is the absolute position of a found item or zero.
Here is an example:
VAR.$$SRC=12345AB67AB89
VAR.$$FND=AB
STR.FIND|$$SRC|-1|$$FND
VAR.$$POS=$tos$
DBP.Found at: $$POS
ENR.
The result is the second "AB" in the Source-String, starting at byte-position 10.
FIND is case-sensitive. If you do not want that, use VTU. on both the source and the Find-String.
To Replace bytes in a String, use the RPL. - RePLace in String command.
To extract a part out of a String, use the GSS. - GetSplitString command.
If your String is a delimited String (like a .csv-file), use:
• SBD. - String between Delimiter
• SBM. - String between Delimiter-Multiple
Syntax
STR.FIND|P1|P2|P3
Parameter Explanation
P1 - Source variable
P2 - numeric parameter, will be completely resolved. Starting position for search, can be negative to search from the end of the string (reverse direction). Binary compatible variable resolution.
P3 - String to search for. Binary compatible variable resolution.
Example
'*************************************
' STR.FIND
'*************************************
VAR.$$SRC=12345AB6789
VAR.$$FND=AB
STR.FIND|$$SRC|1|$$FND
VAR.$$POS=$tos$
DBP.Found at: $$POS
ENR.
'*************************************
' STR.FIND, search from end of string
'*************************************
VAR.$$SRC=12345AB67AB89
VAR.$$FND=AB
STR.FIND|$$SRC|-1|$$FND
VAR.$$POS=$tos$
DBP.Found at: $$POS
ENR.
Remarks
Variables inside the source P1 are only resolved once. Therefore it can be safely used for binary data. Specialfolders and systemvariables etc. are not resolved, to avoid unwanted changes in binary data.
Limitations:
-
See also:
• 1.5.2 Working with Text-Strings
• VAR. - Variable Set Value/Clear
• IVS. / NVS. - If-Variable-String
• SBD. - String between Delimiter
• SBM. - String between Delimiter-Multiple