<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > !DIC.-Delimited Item Commands > DIC.Swap |
MiniRobotLanguage (MRL)
DIC.Swap
Exchange two Fields inside a Delimited String
Intention
Assume you have a Line like this:
AA;BB;CC;DD;EE;FF
as you can read it Line-by-line out of a csv.-file
Now, you decide that you want to insert Columns before "A" and before "E".
' This is the delimiter character
VAR.$$DEL=;
' This is the Line that has delimited items
VAR.$$LIN=AA;BB;CC;DD;EE;FF
' Theseare the two fields to be exchanged
VAR.$$INA="A"
VAR.$$INB="E"
' Now we call the command
DIC.Swap|$$DEL|$$LIN|$$INA|$$INB|$$RES
' And Debug-Print the Result
DBP.$$RES
ENR
And this is the result: EE;BB;CC;DD;AA;FF
Syntax
DIC.Swap|P1|P2|P3|P4[|P5]
Parameter Explanation
P1 - Delimiter, can be a Single character like semicolon or multiple characters like $crlf$. This is the specified delimiter that delimits the fields in the specified Line P2.
P2 - Line with delimited Items.
P3 - Variable with Index of Fields A to Swap with Field in P4.
Can be Single number like 1 or can be an Letter like "A". You can give a comma-separated list with Numbers of the fields to get.
P4 - Variable with Index of Fields B to Swap with Field in P3.
Can be Single number like 1 or can be an Letter like "A". You can give a comma-separated list with Numbers of the fields to get.
P5 - (optional) Variable for Result. If omitted result is placed on TOS.
Example
'***********************************
' DIC.Swap - Sample
'***********************************
' This is the delimiter character
VAR.$$DEL=;
' This is the Line that has delimited items
VAR.$$LIN=AA;BB;CC;DD;EE;FF
' Theseare the two fields to be exchanged
VAR.$$INA="A"
VAR.$$INB="E"
' Now we call the command
DIC.Swap|$$DEL|$$LIN|$$INA|$$INB|$$RES
' And Debug-Print the Result
DBP.$$RES
' Result:
' EE;BB;CC;DD;AA;FF
ENR
Remarks
-
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