SPLIT
splits a string at a given delimiter value.
Function category: Text​
SPLIT(arg1, arg2, [arg3], [arg4])
Arguments | Description |
| A string. |
| Text delimiter |
| Optional. A Boolean for whether or not to divide text around each character contained in the delimiter (default is false). |
| Optional. A Boolean for whether or not to remove empty string values generated by consecutive delimiters. |
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 the list into separate stringsSPLIT(data.parts.part_1, ", ")​# Returns ["Toyota", "Hyundai", "Kia", "Mercedes Benz"]
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"]
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 stringsSPLIT(data.parts.part_3, ",", false, true)​# Returns ["Audi", "Volkswagen", "Jeep", "Dodge"]
# When arg4 is false, retain empty stringsSPLIT(data.parts.part_3, ",", false, true)​# Returns ["Audi", "", "Volkswagen", "", "Jeep", "", "Dodge"]