String Operations

<< Click to Display Table of Contents >>

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

String Operations

STR.Right / STR.rgt

Previous Top Next


MiniRobotLanguage (MRL)

 

STR.Right

Extract Characters from the Right of a String

 

 

clip1147

Extract a specified number of characters from the right end of a string.

 

Intention

 

The STR.Right command extracts a specified number of characters from the right end of a source string (P1) and stores the result in a destination variable (P3) or overwrites the source string if P3 is omitted. A positive count extracts characters from the end, while a negative count extracts all characters starting from the specified position from the left. This command is useful for retrieving suffixes, trimming strings, or handling binary data.

A positive P2 extracts the last P2 characters from P1.

A negative P2 extracts all characters starting from position |P2| + 1 (equivalent to LEN(P1) - ABS(P2)).

The command is safe for binary data, as variables in P1 are resolved only once.

If P2 is zero or the source string is empty, the result is an empty string.

 

Syntax

 

STR.Right|P1|P2[|P3]

STR.rgt|P1|P2[|P3]

 

Parameter Explanation

 

P1 - (Source String) The string from which to extract characters.

P2 - (Number of Characters) A numeric value specifying the number of characters to extract. Positive values extract from the right; negative values extract from position |P2| + 1 to the end. Resolved to an integer.

P3 - (Optional Result Variable) The variable to store the result. If omitted, the source string (P1) is overwritten.

 

Examples

 

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

' Example 1: Extract a suffix to a result variable

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

VAR.$$SRC=HelloWorld

STR.Right|$$SRC|5|$$RES

' $$RES will contain "World"

MBX.$$RES

ENR.

 

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

' Example 2: Extract all but the first characters

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

VAR.$$SRC=HelloWorld

STR.rgt|$$SRC|-2

' $$SRC will contain "lloWorld" (all but the first 2 characters)

MBX.$$SRC

ENR.

 

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

' Example 3: Invalid count or empty string

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

VAR.$$SRC=HelloWorld

STR.Right|$$SRC|0|$$RES

' $$RES will contain "" (zero count)

MBX.$$RES

STR.Right|$$SRC|20|$$RES

' $$RES will contain "HelloWorld" (entire string, excessive count)

MBX.$$RES

VAR.$$SRC=

STR.Right|$$SRC|5|$$RES

' $$RES will contain "" (empty source string)

MBX.$$RES

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 is resolved to an integer; non-integer values are rounded down.

- If P2 is greater than the length of P1, the entire source string is returned.

- If P2 is zero or negative and exceeds the string length, an empty string is returned.

- The command is efficient for extracting suffixes or trimming beginnings of strings.

- For extracting from the left, use STR.Left; for specific positions, use STR.MidStr or STR.MidTo.

 

Limitations:

- P2 must be an integer; non-integer values are rounded down.

- No case-insensitive variant available.

 

See also:

STR.Left

STR.MidStr

STR.MidTo

STR.Overwrite

STR.Patch

STR.Delete

STR.DeleteTo

STR.Retain

STR.CiRetain

STR.RetainAny

STR.Clone

STR.Reverse

RPL. - RePLace in String