String Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > String commands > !STR.- String Command >

String Operations

STR.Patch

Previous Top Next


MiniRobotLanguage (MRL)

 

STR.PATCH

String commands

 

 

Intention

 

PATCH - Mode: This Mode combines the DELETE and the INSERT Mode into one command. Unlike the OVERWRITE-Mode, this Mode can change the length of a String if needed. Here is a simple example:

 

VAR.$$SRC=12345XX89

' These characters will be inserted

VAR.$$NEW=67

' Starting position is byte 6

VAR.$$POS=6

' DELETE 2 characters

VAR.$$DEL=2

STR.PATCH|$$SRC|$$POS|$$DEL|$$NEW

MBX.$$SRC

ENR.

 

The result is as expected:

 

graphic

 

You can also use a negative P2, in that case the position will be calculated from the end of the string (reverse direction). Like this:

 

VAR.$$SRC=12345XX89

VAR.$$NEW=67

VAR.$$POS=-4

VAR.$$DEL=2

STR.PATCH|$$SRC|$$POS|$$DEL|$$NEW

MBX.$$SRC

ENR.

 

The result is the same like before, as the position "-4" is the same character then the position "6", if the total string length is 9.

 

You can use the STR.PATCH command also as a replacement for the STR.DELETE command, if you do specify an empty Insert-parameter P4. That works, because if P4 is empty then the INSERT-Part will be skipped and only the DELETE will be made. Like this:

 

VAR.$$SRC=12345XX89

VAR.$$NEW=

VAR.$$POS=-4

VAR.$$DEL=2

STR.PATCH|$$SRC|$$POS|$$DEL|$$NEW

MBX.$$SRC

ENR.

 

The result is this:

graphic

 

In the same way, you can have the DELETE-Part skipped, if you specify a zero for P3. This is the number of characters to be deleted. Of course if P3 is zero, nothing is going to be deleted. Instead the complete DELETE part is being skipped. In that case the INSERT Part will be executed, if P4 is not empty. Here is an example:

 

VAR.$$SRC=12345XX89

VAR.$$NEW=67

VAR.$$POS=-4

VAR.$$DEL=0

STR.PATCH|$$SRC|$$POS|$$DEL|$$NEW

MBX.$$SRC

ENR.

 

The result is just the INSERTed string, and nothing deleted.

 

graphic

 

Using the STR.PATCH command on many large strings ( >100 MB) may be significantly slower then using the STR.OVERWRITE command. Therefore prefer the STR.OVERWRITE, if the String that is inserted has the same length as the string that is been deleted.

 

 

 

 

Syntax

 

STR.PATCH|P1|P2|P3|P4

 

 

Parameter Explanation

 

P1 - source and destination variable

 

P2 - numeric parameter, will be completely resolved.

    Starting position of the DELETE/INSERT operations.

 

P3 - numeric parameter, will be completely resolved. Number

    of bytes to delete, starting at the position P2. If P3

    evaluates to zero, nothing is deleted. Then only the

    INSERT is been done.

 

P4 - Insert-String, String that is inserted. If Length of P4

  evaluates to zero, nothing will be inserted. In this case the

    PATCH command will work somehow like DELETE (P2 is count here,

    while it is a position in DELETE).

 

 

 

 

Example

 

'*************************************

' STR.PATCH

'*************************************

VAR.$$SRC=12345XX89

' These characters will be inserted

VAR.$$NEW=67

' Starting position is byte 6

VAR.$$POS=6

' DELETE 2 characters

VAR.$$DEL=2

STR.PATCH|$$SRC|$$POS|$$DEL|$$NEW

MBX.$$SRC

ENR.

 

 

'*************************************

' STR.PATCH (INSERT MODE)

'*************************************

VAR.$$SRC=12345XX89

VAR.$$NEW=67

VAR.$$POS=-4

VAR.$$DEL=0

STR.PATCH|$$SRC|$$POS|$$DEL|$$NEW

MBX.$$SRC

ENR.

 

 

'*************************************

' STR.PATCH (DELETE MODE)

'*************************************

VAR.$$SRC=12345XX89

VAR.$$NEW=

VAR.$$POS=-4

VAR.$$DEL=2

STR.PATCH|$$SRC|$$POS|$$DEL|$$NEW

MBX.$$SRC

ENR.

 

 

 

 

Remarks

 

Variables inside the source P1 and P4 are only resolved once. Therefore it can be safely used for binary data. Specialfolders and systemvariables 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

    VAS. - Variable with String

    RPL. - RePLace in String

    IVS. / NVS. - If-Variable-String

    GSS. - GetSplitString

    GFS. - Get-Filtered-String

    GES. - Get-Extracted-String

    SBD. - String between Delimiter

    SBM. - String between Delimiter-Multiple

    FEM. - For Each Member

    LEN. - Length-of-String