String Operations

<< Click to Display Table of Contents >>

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

String Operations

STR.DeleteTo

Previous Top Next


MiniRobotLanguage (MRL)

 

STR.DeleteTo

Delete a Range of Characters from a String by Position

 

Delete characters by position

Remove characters from a source string between specified start and end positions.

 

Intention

 

The STR.DeleteTo command removes a range of characters from a source string, defined by a start position (P2) and an end position (P3), and modifies the source string directly.

The range is inclusive, deleting all characters from the start to the end position. This command is useful for removing specific substrings, whitespace, or binary data segments.

It is safe for binary data, as variables in the source string are resolved only once, preventing unwanted substitutions.

For deleting a specified number of characters (to the right or left), use STR.Delete instead.

The range is inclusive, deleting characters from P2 to P3 (both positions included).

Positions are 1-based and must be positive integers within the string length.

If P2 or P3 is invalid (e.g., zero, negative, or beyond string length) or P2 > P3, no deletion occurs.

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

 

Syntax

 

STR.DeleteTo|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 of the range to delete. Resolved to an integer.

P3 - (End Position) A numeric value specifying the 1-based ending position of the range to delete (inclusive). Resolved to an integer.

 

Examples

 

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

' Example 1: Delete a substring by position

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

VAR.$$SRC=12345AB6789

STR.DeleteTo|$$SRC|6|7

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

MBX.$$SRC

ENR.

 

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

' Example 2: Delete leading spaces

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

VAR.$$SRC= HelloWorld

STR.DeleteTo|$$SRC|1|3

' $$SRC will contain "HelloWorld" (deletes three spaces at positions 1-3)

MBX.$$SRC

ENR.

 

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

' Example 3: Invalid range (no deletion)

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

VAR.$$SRC=HelloWorld

STR.DeleteTo|$$SRC|6|4

' $$SRC remains "HelloWorld" (invalid range, P2 > P3)

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.

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

- For deleting a specified number of characters (including to the left), use STR.Delete.

 

Limitations:

- P2 and P3 must be positive integers within the string length, and P2 must not exceed P3; 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.Delete

STR.Retain

STR.CiRetain

STR.RetainAny

STR.Clone

RPL. - RePLace in String

GSS. - GetSplitString