Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
Dan Gorman edited this page Sep 21, 2018 · 3 revisions

The SPLIT Function

SPLIT splits a string around a given delimiter value.

Syntax

SPLIT(arg1, arg2, [arg3])

  • arg1 is a string
  • arg2 is the text delimiter
  • arg3 is optional, and is a boolean for whether or not divide text around each character contained in delimiter (default is false)
  • arg4 is optional, and is a boolean for whether or not to remove empty string values generated by consecutive delimiters

Uses

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:

{  
   "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 would return ["Toyota", "Hyundai", "Kia", "Mercedes Benz"].

Other Examples

If we invoke the third argument, any string that matches a character in the delimiter will be a split location:

SPLIT(data.parts.part_2, "MAKE:", TRUE) => ["B", "W", "ercedes Benz", "Ford", "Tesla"]

SPLIT(data.parts.part_2, "MAKE:", FALSE) => ["BMW", "Mercedes Benz", "Ford", "Tesla"]

SPLIT(data.parts.part_2, "MAKE:") => ["BMW", "Mercedes Benz", "Ford", "Tesla"]

If we provide a value for the fourth argument, any empty strings will be removed:

SPLIT(data.parts.part_3, ",", false, true) => ["Audi", "Volkswagen", "Jeep", "Dodge"]

SPLIT(data.parts.part_3, ",", false, false) => ["Audi", "", "Volkswagen", "", "Jeep", "", "Dodge"]

Clone this wiki locally