arraySplit
Description
Returns an array of substrings by splitting a string using the specified delimiter.
- The delimiter can be either a
stringor aregexp.
Syntax
Like many functions in DataPrime, arraySplit supports two notations, function and method. These interchangeable forms allow flexibility in how you structure expressions.
- Function notation
- Method notation
arraySplit(string: string, delimiter: regexp | string): array<string>
(string: string).arraySplit(delimiter: regexp | string): array<string>
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
string | string | true | The string to split |
delimiter | regexp | string | true | The delimiter used to split the string |
Example
Use case: Extract first and last names from a full name
Suppose you have a field containing a full name. Consider the following input:
{
"name": "Al Gorithm"
}
By splitting the name field on a space, you can extract the first and last names into separate fields.
Example query
- Function notation
- Method notation
create first_name from arraySplit(name, ' ')[0]
| create last_name from arraySplit(name, ' ')[1]
create first_name from name.arraySplit(' ')[0]
| create last_name from name.arraySplit(' ')[1]
Example output
The result will include new fields for the first and last names:
{
"name": "Al Gorithm",
"first_name": "Al",
"last_name": "Gorithm"
}