<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > String Operations |
MiniRobotLanguage (MRL)
RPL. Command
RePLace in string
Intention
This command can be used to replace parts of a string with another.
There are several options, which can be handy, if you want to replace in binary strings or for special tasks.
Syntax
RPL.P1|P2|P3[|P4]
Parameter Explanation
P1 - Source and Destination
P2 - Replace-String (this one is replaced)
P3 - with-String (this is what it is replaced with)
P4 - Options, see below:
You can only specify one flag for RPL. as P4.
These are the flags for P4:
a - "ANY" & binary-compatible.
Using this one you will replace single letters
with single letters.
b - binary compatible does not resolve special-folders or
system-variables
c - "ANY" using this one you will replace single letters
with single letters. Not binary compatible.
e - Equalcase-Replace. Replace is done in Equalcase-Mode,
the Result will anyway keep its case.
f - fast replace. Default mode if no option is specified.
w - "Whole Words Algo"-Mode. in this mode only words are replaces
and only if they are not enclosed in " ".
First Parameter is a Variable, local or Global.
If invalid ("-") for example, Stack is used.
Speed in Ticks:
This command uses typically around 170 to 230 Ticks heavily depending on Parameters.
Example
'***********************************
' RPL.-Test
'***********************************
PRT. Do a Fast-Replace
: $$TXT=Hallo "PETER",Peter, PETER when PETERSCHMIDT...
: §§REP=PETER
: §§WIT=RALF
PRT.$$TXT
RPL.$$TXT|§§REP|§§WIT
PRT.$$TXT
PRT.-------------------------------
PRT. Do a Equalcase-Replace
: $$TXT=Hallo "PETER",Peter, PETER when PETERSCHMIDT...
: §§REP=PETER
: §§WIT=RALF
PRT.$$TXT
RPL.$$TXT|§§REP|§§WIT|e
PRT.$$TXT
PRT.-------------------------------
PRT. Use "whole-word Algo"
: $$TXT=Hallo "PETER",Peter, PETER when PETERSCHMIDT...
: §§REP=PETER
: §§WIT=RALF
PRT.$$TXT
RPL.$$TXT|§§REP|§§WIT|w
PRT.$$TXT
PRT.-------------------------------
PRT. Use "any matchstring"
: $$TXT=Hallo "PETER",Peter, PETER when PETERSCHMIDT...
: §§REP=PETER
: §§WIT=RALF
PRT.$$TXT
RPL.$$TXT|§§REP|§§WIT|c
PRT.$$TXT
PRT.-------------------------------
DMP.
END.
'***********************************
' RPL.-Sample
' Here we use RPL to replace Text in
' a line-based Textfile
' We search for a Date like 11.?7.*
' and replace it with 12.08.2015
'***********************************
$$FIL=?path\Test.txt
$$TAR=?path\Target.txt
' Delete it if it existed before
DEL.$$TAR
' We search for the line with the date
$$SRC=11.?7.*
' New date - we replace the old one with this
$$NEW=12.08.2015
FIF.tww|$$FIL|$$SRC
JIZ.$$000|Lab_nf
$$LIN=$$000
$$STA=$$000
$$END=$$000
$$STR=$$000
$$TRE=$$000
PRT.String: $$STR Found in Line: $$LIN
PRT.From Character $$STA to $$END
GLC.$$FIL|$$REA
' Line where String is minus 1
CAL.$$TOL=$$LIN-1
' Copy all lines until the wanted Line
FOR.$$COP|1|$$TOL
LFF.$$FIL|$$COP|$$RES
' We use the delimiter that was found in the source file
$$TXT=$$RES$$TRE
ATF.$$TAR|$$TXT
NEX.
' Here is the Line with the date
LFF.$$FIL|$$LIN|$$TXA
RPL.$$TXA|$$STR|$$NEW
$$TXB=$$TXA$$TRE
ATF.$$TAR|$$TXB
' Now copy Rest of file
' Line where String is plus 1
CAL.$$TOL=$$LIN+1
FOR.$$COP|$$TOL|$$REA
LFF.$$FIL|$$COP|$$RES
' We use the delimiter that was found in the source file
$$TXT=$$RES$$TRE
ATF.$$TAR|$$TXT
NEX.
:Lab_nf
MBX.!
ENR.
Remarks
If you use the ANY option, within MainString, each occurrence of each character in MatchString will be replaced with the corresponding character in NewString. In this case, MatchString and NewString must be the same length, because there is a one-to-one relation.
"|w" - replaces only whole words (no words in word, no words in qoutes) in text but not within double quotes
Limitations:
Due to speed-reasons, "|w"-Algo has the limitation, that the result-string cannot exceed the source in size by more then 100 KB.
If you need more then just append enough spaces to the source string before.
This limitation should never be a problem in practical use.
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