Skip to content

arraySplit

Description

Returns an array of substrings by splitting a string using the specified delimiter.

  • The delimiter can be either a string or a regexp.

Syntax

Like many functions in DataPrime, arraySplit supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

arraySplit(string: string, delimiter: regexp | string): array<string>
(string: string).arraySplit(delimiter: regexp | string): array<string>

Arguments

NameTypeRequiredDescription
stringstringtrueThe string to split
delimiterregexpstringtrue

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": "Chris Cooney"
}

By splitting the name field on a space, you can extract the first and last names into separate fields.

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]

Output

The result will include new fields for the first and last names:

{
    "name": "Chris Cooney",
    "first_name": "Chris",
    "last_name": "Cooney"
}