Skip to content

arraySplit - Splits string into array of tokens

arraySplit will split a string on some delimiter, and return the array of each split component of the string.

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 into an array
delimiterregexpstringtrue

Example - Parse first & last name from full name

Consider the following document:

{
    "name": "Chris Cooney"
}

We may wish to break up this name, so that we can track family name and look for similarities across documents:

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]

This results in the following document:

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