<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > !Delimited Strings > String Operations |
MiniRobotLanguage (MRL)
SBD. Command
String Between Delimiter
Intention
Return a delimited part of a string. A example for a delimited string is a "csv" file from Excel. It could look like this:
VAR.$$TXT=Name,Last Name,Zip-Code
In this case the comma is the delimiter. Using the SBD.-command you can get any part of such delimited strings. Usage is like this:
VAR.$$TXT=Name,Last Name,Zip-Code
SBD.$$TXT|,|2|$$RES
DBP.$$RES
Will return "Last name", as its the second part in the delimited string.
There is another mode of operation. Imagine the delimiter is a PIPE-Sign "|". Now the PIPE-Sign is the delimiter for the command itself, how could we do that?
We can do that with the second operation mode, we use P5. When we specify P5 then we can change the delimiter for the command itself. It's as easy as this:
' Here we have a string that is delimited with PIPE's
VAR.$$TXT=Name|Last Name|Zip-Code
' We tell SBD. that we use the comma as command-delimiter (see P5)
SBD.,$$TXT,|,2,$$RES
DBP.$$RES
As alternative, you can use the RPL.-command and replace all Pipes with something else before using SBD.
In this case only one SBD. command is used to extract multiple parts of a delimited string to five variables: $$V01 to $$V05.
'#EXE:?path\
'#SPI:ForceWrite
VAS.$$SRC=12*34*45*67*89
' We remove leading and trailing delimiters first
VBT.$$SRC|*
' We replace double delimiters next
$$REP=**
$$WIT=*
RPL.$$SRC|$$REP|$$WIT
' Get number of delimited elements
GSC.$$SRC|*|$$CNT|d
' Split the delimited parts
FOR.$$LOP|1|$$CNT
SBD.$$SRC|*|$$LOP|$$RES
' Construct output variable
VAN.$$VON=$$LOP
FMT.$$VON|00
VAR.$$VAR=$$V$$VON
' Store into output variable
VAI.$$VAR=$$RES
NEX.
' Print the 5 Variables
PRT.$$V01
PRT.$$V02
PRT.$$V03
PRT.$$V04
PRT.$$V05
MBX.!
ENR.
Syntax
SBD.[P5]P1|P2|P3[|P4]
Parameter Explanation
P1 - STR Source string from which the part should be extracted.
P2 - Delimiter inside the source string.
P3 - Index of delimited string-item to be extracted
P4 - optional Variable for result. If omitted, result goes to TOS.
P5 - optional SINGLE CHAR. Delimiter for SBD itself. Cannot be "$"
or "§". If omitted its "|".
Example
' Example for SBD. Result is "das"
: $$TAR=Hallo Peter das ist ein Satz.
: $$IDX=3
SBD.$$TAR|$SP$|$$IDX|$$TAR
PRT.Result is: $$TAR
DMP.
END.
' Example 2 for SBD. Result is "das"
: $$TAR=Hallo|Peter|das|ist|ein|Satz.
: $$IDX=3
SBD.!$$TAR!|!$$IDX!$$TAR
PRT.Result is: $$TAR
DMP.
END.
Remarks
-
Limitations:
-
See also:
• 1.5.2 Working with Text-Strings
• SBM. - String between Delimiter-Multiple
• VAR. - Variable Set Value/Clear
• IVS. / NVS. - If-Variable-String
• SBD. - String between Delimiter
•