SPLIT

SPLIT splits a string around a given delimiter value.

Function category: Text

Syntax

SPLIT(arg1, arg2, [arg3], [arg4])

Arguments

Description

arg1

A string.

arg2

Text delimiter

arg3

Optional. A boolean for whether or not to divide text around each character contained in the delimiter (default is false).

arg4

Optional. A boolean for whether or not to remove empty string values generated by consecutive delimiters.

Examples

Example 1: Make easily parse-able version

Let's say we're given a response with a list of car manufacturers for a given part but each list is in a single string which makes parsing it difficult:

{
"data":{
"parts":{
"part_1": "Toyota, Hyundai, Kia, Mercedes Benz",
"part_2": "MAKE:BMW, MAKE:Mercedes MAKE:Benz, MAKE:Ford, MAKE:Tesla",
"part_3": "Audi,,Volkswagen,,Jeep,,Dodge"
}
}
}

If we want to compile an easier-to-parse version of the companies associated for a given part, we can use SPLIT:

SPLIT(data.parts.part_1, ", ")

This returns the following:

["Toyota", "Hyundai", "Kia", "Mercedes Benz"]

Example 2: Strings that match a character in delimiter

If we invoke arg3, any string that matches a character in the delimiter will be a split location. In this example, the delimiter is "MAKE:".

arg3 is true (that is, any string that has one of the characters in "MAKE:"):

SPLIT(data.parts.part_2, "MAKE:", TRUE)

This results in the following (two strings have M):

["B", "W", "ercedes Benz", "Ford", "Tesla"]

arg3 is false (do not use "MAKE:"):

SPLIT(data.parts.part_2, "MAKE:", FALSE)

This results in the following:

["BMW", "Mercedes Benz", "Ford", "Tesla"]

No arg3 provided (same as false):

SPLIT(data.parts.part_2, "MAKE:")

This results in the following:

["BMW", "Mercedes Benz", "Ford", "Tesla"]

Example 3: Remove empty strings

If we provide a value for arg4, any empty strings will be removed in "part_3".

True:

SPLIT(data.parts.part_3, ",", false, true)

This results in the following:

["Audi", "Volkswagen", "Jeep", "Dodge"]

False:

SPLIT(data.parts.part_3, ",", false, false)

This results in the following:

["Audi", "", "Volkswagen", "", "Jeep", "", "Dodge"]