<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > String Operations |
MiniRobotLanguage (MRL)
GSS. Command
Get Split String
Intention
Returns a part of a string/text. If you have a text/string and you want just a part of it, think of GSS. Usage is easy:
VAR.$$TXT=My name is Peter, Tel.12345
DBP.$$TXT
' The result is the complete text
' Now we are going to split this string into pieces
' We put the left two characters into $$RES
GSS.1|2|$$TXT|$$RES
DBP.$$RES
' The result is "My"
' We put the right five characters into $$RES
GSS.-5|-1|$$TXT|$$RES
DBP.$$RES
' The result is "12345"
' We put characters 3 to 8 into $$RES
GSS.3|8|$$TXT|$$RES
DBP.$$RES
' The result is "name"
Syntax
GSS.P1|P2[|P3][|P4]
Parameter Explanation
P1 - Starting position
P2 - Ending position
P3 - Source Variable
P4 - Target Variable
There are three versions of GSS. depending on how many parameters are specified.
The first two position parameters must always be given.
If P1 or P2 are negative, the character is counted starting from end of source-string backwards to the first character on the string.
GSS.P1|P2
The Source String is taken from TOS.
P1 gives the first character of the substring.
P2 gives the last character of the substring to extract.
The Result is been placed on TOS.
GSS.P1|P2|P3
The Source String is taken from P3.
P1 gives the first character of the substring.
P2 gives the last character of the substring to extract.
The Result is been placed on TOS.
GSS.P1|P2|P3|P4
The Source String is taken from P3.
P1 gives the first character of the substring.
P2 gives the last character of the substring to extract.
P4 takes the Result.
For all three versions of GSS.:
If P1 or P2 are negative, the character is been counted from end of source-string.
Example
'***********************************
' GSS.-DEMO
'***********************************
' GSS needs at least two parameters
' String total len=11
: §§TXT=ABCDEFGHIJK
PUV.§§TXT
DMP.4
GSS.2|3
DMP.4
PRT.-------------------------
PUV.§§TXT
DMP.4
GSS.-6|-4
DMP.4
PRT.-------------------------
PUV.§§TXT
DMP.4
: §§NUM=4
GSS.(§§NUM+1)|(-§§NUM)|§§SRC|§§RES
PRT.Result: >§§RES<
DMP.
END.
Remarks
Variables inside the source are only resolved if the length of the source string is 5.
Therefore it can safely be used fort for Binary data.
For the same reason, Special-Characters 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