Array -Commands

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Arrays and Data-Structures > Array -Commands > !INT-Arrays >

Array -Commands

ARR.Parse INT

Previous Top Next


MiniRobotLanguage (MRL)

 

ARR.Parse INT

Parse a String into an Integer Array Using a Delimiter

 

 

clip1169

Split a source string into integer array elements based on a specified or default delimiter.

 

Intention

The ARR.Parse INT command splits a source string (P2) into elements and stores them as 64-bit signed integers in a specified integer array (P1) using a delimiter (P3). If the delimiter is omitted, a comma (",") is used by default. The command is designed for processing delimited numeric data, such as lists of integers, into an array for tasks like data analysis or arithmetic operations. The number of successfully parsed elements is returned on the Top of Stack (TOS). Internally, values are stored as strings, consistent with MRL’s array storage mechanism.

Array Number: The array is specified by a number (0–32), which is modified in-place with the parsed integer elements.

Delimiter: A string that separates elements in the source string. Defaults to "," if omitted or empty.

Integer Validation: Each element must be a valid 64-bit signed integer; non-integer values are skipped.

Return Value: The number of valid integer elements parsed is pushed to the TOS.

Binary Safety: The command is binary-safe for the source string and delimiter, handling special characters or null bytes.

 

Schematic (Integer Array Parsing)

Source String: 42,123,-56

Command: ARR.Parse INT|1|42,123,-56|,

Result Array[1]: ["42", "123", "-56"]

TOS: 3 (number of valid integers parsed)

 

Syntax

ARR.Parse INT|P1|P2[|P3]

 

Parameter Explanation

 

P1 - Array Number: Specifies the integer array number (0–32) to store the parsed elements. Resolved to an integer.

P2 - Source String: The string containing delimited integer values. Can be a variable or literal.

P3 - Delimiter (Optional): The string used to split P2. Defaults to "," if omitted or empty.

 

Examples

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

' Example 1: Parse with default delimiter

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

VAR.$$SRC=42,123,-56

ARR.Parse INT|1|$$SRC

' Array 1 contains: ["42", "123", "-56"]

ARR.Get INT Array|1|1|$$RET

MBX.$$RET

ENR.

 

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

' Example 2: Parse with custom delimiter

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

VAR.$$SRC=10;20;30

ARR.Parse INT|2|$$SRC|;

' Array 2 contains: ["10", "20", "30"]

ARR.Get INT Array|2|2|$$RET

MBX.$$RET

ENR.

 

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

' Example 3: Parse empty string

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

VAR.$$SRC=

ARR.Parse INT|3|$$SRC

' Array 3 contains: []

POP.$$CNT

MBX.$$CNT

ENR.

 

'============================================================

' SELF-VALIDATING TEST SCRIPT for ARR.Parse INT

' Purpose: Verify functionality with JIV. for automated checks.

' Tests default delimiter, custom delimiter, empty string, invalid parameters, and non-integer values.

'============================================================

' Initialize counters

$$PAS=0

$$FAI=0

STS.CLEAR

PRT. ===================================================

PRT. Test 1.1: Parse with default delimiter

STS.CLEAR

ARR.Clr|1

VAR.$$SRC=42,123,-56

ARR.Parse INT|1|$$SRC

ARR.Get INT Array|1|1|$$RET

$$EXP=123

JIV.$$RET!$$EXP|Lab_Error1

PRT. -> PASS

VIC.$$PAS

JMP.Lab_Next1

:Lab_Error1

GSB.Test

'-----------------------------------------------------------

:Lab_Next1

PRT. Test 1.2: Parse with custom delimiter

STS.CLEAR

ARR.Clr|2

VAR.$$SRC=10;20;30

ARR.Parse INT|2|$$SRC|;

ARR.Get INT Array|2|2|$$RET

$$EXP=30

JIV.$$RET!$$EXP|Lab_Error2

PRT. -> PASS

VIC.$$PAS

JMP.Lab_Next2

:Lab_Error2

GSB.Test

'-----------------------------------------------------------

:Lab_Next2

PRT. Test 1.3: Parse empty string

STS.CLEAR

ARR.Clr|3

VAR.$$SRC=

ARR.Parse INT|3|$$SRC

POP.$$CNT

$$EXP=0

JIV.$$CNT!$$EXP|Lab_Error3

PRT. -> PASS

VIC.$$PAS

JMP.Lab_Next3

:Lab_Error3

GSB.Test

'-----------------------------------------------------------

:Lab_Next3

PRT. ===================================================

PRT. TEST SUMMARY

PRT. ===================================================

CAL.$$TOT=$$PAS+$$FAI

$$MSG=Total Tests: $$TOT

PRT.$$MSG

$$MSG=Passed: $$PAS

PRT.$$MSG

$$MSG=Failed: $$FAI

PRT.$$MSG

JIV.$$FAI=0|Lab_Success

$$MSG=FAILURE: $$FAI of $$TOT tests failed.

MBX.$$MSG|Test Result|16

JMP.Lab_End

:Lab_Success

MBX.SUCCESS: All tests passed!|Test Result|64

:Lab_End

ENR.

:Test

$$MSG= -> FAIL - Result: $$RET (exp: $$EXP)

PRT.$$MSG

VIC.$$FAI

RET.

 

 

Remarks

- The command is binary-safe, handling special characters or null bytes in the source string or delimiter.

- P1 is resolved to an integer; non-integer values are rounded down.

- If P3 is empty or omitted, the default comma (",") is used as the delimiter.

- Non-integer elements in the source string are skipped, and the TOS reflects only valid integer elements parsed.

- The array is cleared before parsing, ensuring no residual elements remain.

 

Limitations

- Array numbers are limited to 0–32, consistent with other MRL array commands.

- Invalid array numbers (e.g., negative or >32) result in no operation.

- Requires 2 or 3 parameters; fewer or more parameters result in no operation.

- Non-integer values in the source string are skipped, potentially reducing the number of elements parsed.

- No support for multidimensional arrays or complex parsing patterns.

 

See also:

ARR.Set INT Array

ARR.Get INT Array

ARR.Clr

ARR.Dim

ARR.Parse