String Operations

<< Click to Display Table of Contents >>

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

String Operations

STR.GrabDelimited

Previous Top Next


MiniRobotLanguage (MRL)

 

STR.GrabDelimited

Extracts the Nth delimited field from a string.

 

 

 

Intention

 

This Command extracts a specific field from a delimited string (like CSV or pipe-delimited data). You specify the delimiter and the field number, and the command returns that field's content.

This is similar to the PARSE command but specifically designed for simple delimiter-separated values.

 

 

Syntax

 

STR.GrabDelimited|P1|P2|P3|P4

 

Parameter Explanation

 

P1 - (Input, Text) The source string containing delimited fields.

P2 - (Input, Text) The delimiter character(s) separating fields.

P3 - (Input, Numeric) The 1-based index of the field to extract.

P4 - (Output, Text) Variable to store the extracted field content.

 

 

 Extracting Delimited Fields

 

Source: "Apple,Banana,Cherry,Date"

Delimiter: ",", Field: 3

Result: "Cherry"

 

Source: "Name|Age|City"

Delimiter: "|", Field: 2

Result: "Age"

 

 

 

Example

 

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

' STR.GrabDelimited Example

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

$$CSV="John,Doe,30,Engineer"

' Get the last name (field 2)

STR.GrabDelimited|$$CSV|,|2|$$LASTNAME

' $$LASTNAME = "Doe"

MBX.Last name: $$LASTNAME

 

' Parse pipe-delimited record

$$RECORD="INV-001|2024-01-15|$150.00|Pending"

' Get the amount (field 3)

STR.GrabDelimited|$$RECORD|||3|$$AMOUNT

' $$AMOUNT = "$150.00"

MBX.Amount: $$AMOUNT

 

' Extract first field

$$DATA="KEY=VALUE"

STR.GrabDelimited|$$DATA|=|1|$$KEY

' $$KEY = "KEY"

MBX.$$KEY

ENR.

 

Remarks

 

? Field index is 1-based (first field = 1).

? If the field index exceeds the number of fields, an empty string is returned.

? The delimiter can be multiple characters.

? For CSV parsing with quoted fields, use STR.Parse instead.

 

See also:

 

? STR.Parse - Parse with delimiter

? STR.Split - Split to array

? STR.GrabQuoted - Extract quoted string