String Operations

<< Click to Display Table of Contents >>

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

String Operations

STR.Delete

Previous Top Next


MiniRobotLanguage (MRL)

 

STR.Delete

Delete a Specified Number of Characters from a String

 

clip1133

Remove a specified number of characters from the source string, to the right or left.

 

Intention

 

The STR.Delete command removes a specified number of characters from a source string, starting at a given position. The deletion can occur to the right (if the count is positive) or to the left (if the count is negative), and the source string is modified directly. This is useful for removing unwanted portions of a string, such as specific substrings, whitespace, or binary data segments. The command is safe for binary data, as variables in the source string are resolved only once, preventing unwanted substitutions.

The start position is 1-based and specifies where the deletion begins.

A positive count deletes characters to the right of the start position; a negative count deletes characters to the left.

If the count is zero, negative, or the range is invalid (e.g., beyond string length), no deletion occurs.

If the source string is empty or the start position is invalid, the source string remains unchanged.

 

Syntax

 

STR.Delete|P1|P2[|P3]

 

Parameter Explanation

 

P1 - (Source and Destination Variable) The string from which characters are deleted. Modified directly with the resulting string.

P2 - (Start Position) A numeric value specifying the 1-based starting position for deletion. Resolved to an integer.

P3 - (Optional Count) A numeric value specifying the number of characters to delete. Positive values delete to the right; negative values delete to the left. Defaults to 1 if omitted. Resolved to an integer.

 

Examples

 

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

' Example 1: Delete a substring to the right

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

VAR.$$SRC=12345AB6789

STR.Delete|$$SRC|6|2

' $$SRC will contain "123456789" (deletes "AB" at positions 6-7)

MBX.$$SRC

ENR.

 

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

' Example 2: Delete characters to the left

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

VAR.$$SRC=12345AB6789

STR.Delete|$$SRC|6|-2

' $$SRC will contain "123AB6789" (deletes "45" at positions 4-5)

MBX.$$SRC

ENR.

 

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

' Example 3: Default deletion (one character)

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

VAR.$$SRC=12345AB6789

STR.Delete|$$SRC|6

' $$SRC will contain "12345B6789" (deletes "A" at position 6)

MBX.$$SRC

ENR.

 

Remarks

- Variables in the source string (P1) are resolved only once, ensuring safety for binary data (e.g., null characters or special sequences).

- P2 and P3 are resolved to integers; non-integer values are rounded down.

- For negative P3, deletion starts at position P2 + P3 and ends at P2 - 1.

- The command is efficient for removing specific ranges, especially in large strings or binary data.

 

Limitations:

- P2 must be a positive integer within the string length; invalid values prevent deletion.

- No option to store the result in a separate variable; P1 is always modified.

- Case-sensitive; no case-insensitive variant available.

 

See also:

STR.DeleteTo

STR.Retain

STR.CiRetain

STR.RetainAny

STR.Clone

RPL. - RePLace in String

GSS. - GetSplitString