<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > !STR.- String Command > String Operations |
MiniRobotLanguage (MRL)
STR.SetMidTo
Replace a Substring in a String from a Start to an End Position forcing the String length to change if necessary
Intention
This command is used to replace a specific sub string within a main string, starting from a given position and ending at another position.
The STR.SetMidTo statement replaces characters in a string variable.
If P3 is omitted, or there aren't enough characters in P1, all remaining characters are removed.
The replacement starts at the position specified by P2 and ends at the position specified by P3.
The source string can grow or condense in size using this command as the String P4 is inserted after removing the specified characters.
Negative values for P2 or P3 are counted backwards from the end of the string.
Syntax
STR.SetMidTo|P1|P2|P3|P4
Parameter Explanation
•P1 - (SourceString, Text) Variable containing the source string.
•P2 - (StartPosition, Numeric) The position where the replacement will start.
•P3 - (EndPosition, Numeric) The position where the replacement will end.
•P4 - (ReplacementString, Text) The string that will replace the substring from P2 to P3.
Example
'***********************************
' STR.-Sample
'***********************************
' Replace characters from position 5 to 8 with 'WXYZ' in the string
$$SRC=ABCDEFGHIJK
$$STA=5
$$END=8
$$REP=WXYZ
STR.SetMidTo|$$SRC|$$STA|$$END|$$REP
ENR.
Result:
$$SRC will now contain 'ABCDWXYZIJK'
Remarks
-
Limitations:
-
See also:
•