SPLIT

SPLIT splits a string at 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

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"
}
}
}

Example 1: Make an easy to parse version

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

# Split the list into separate strings
SPLIT(data.parts.part_1, ", ")
# Returns ["Toyota", "Hyundai", "Kia", "Mercedes Benz"]

Example 2: Split 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:".

# When arg3 is true, split any string having
# a character in "MAKE:"
SPLIT(data.parts.part_2, "MAKE:", TRUE)
# Returns ["B", "W", "ercedes Benz", "Ford", "Tesla"]
# Two strings have M
# When arg3 is false, do not split any string having
# a character in "MAKE:"
SPLIT(data.parts.part_2, "MAKE:", FALSE)
# Returns ["BMW", "Mercedes Benz", "Ford", "Tesla"]
# No arg3 is provided. Same as false.
SPLIT(data.parts.part_2, "MAKE:")
# Returns ["BMW", "Mercedes Benz", "Ford", "Tesla"]

Example 3: Remove an empty strings

If we provide a Boolean value for arg4, any empty string values will be removed in the specified key.

# When arg4 is true, remove empty strings
SPLIT(data.parts.part_3, ",", false, true)
# Returns ["Audi", "Volkswagen", "Jeep", "Dodge"]
# When arg4 is false, retain empty strings
SPLIT(data.parts.part_3, ",", false, true)
# Returns ["Audi", "", "Volkswagen", "", "Jeep", "", "Dodge"]