Skip to content

splitParts

Description

Splits a string using a delimiter and return the token at the specified index. The index starts at 1, not 0.

Syntax

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

splitParts(value: string, delimiter: string, index: number): string
(value: string).splitParts(delimiter: string, index: number): string

Arguments

NameTypeRequiredDescription
valuestringtrueThe string to split
delimiterstringtrueThe delimiter used to split the string
indexnumbertrueThe 1-based index of the token to return

Example

Extract the domain from an email address

Consider the following document:

{
    "email": "chris@coralogix.com"
}

Use splitParts to extract the domain in one step:

create domain from splitParts(email, '@', 2)
create domain from email.splitParts('@', 2)

Output

{
    "email": "chris@coralogix.com",
    "domain": "coralogix.com"
}