<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > !STR.- String Command > Template |
MiniRobotLanguage (MRL)
STR.SetMidToB
Replace a Substring in a String from a Start to an End Position behaving like MID$ in BASIC ("B")
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.SetMidToB statement replaces characters in a string variable.
If P3 is omitted, or there aren't enough characters in P1, all remaining characters are replaced.
The replacement starts at the position specified by P2 and ends at the position specified by P3.
The source string can not grow or condense in size using this command!
Negative values for P2 or P3 are counted backwards from the end of the string.
The number of characters replaced is limited with either the length of the String P4 or the number of given Characters from P2 to P3 .
Both limit the number of characters that will be changed.
Restrictions
The replacement will never extend past the end of P1, meaning STR.SetMidTo cannot alter the length of a string.
If P2 evaluates to a position outside of the string on either side, or if P2 is zero, no operation is performed.
Syntax
STR.SetMidToB|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:
The replacement will never extend past the end of P1, meaning STR.SetMidTo cannot alter the length of a string.
If P2 evaluates to a position outside of the string on either side, or if P2 is zero, no operation is performed.
See also:
•