split_on

Split a string on occurrences of a given separator

Definition

array[string] split_on(string $input, boolean $ignoreEmpty, string *$separators[, ...])

Splits string $input into an array of substrings. Delimiters between substrings are defined in *$separators. *$separators are not included in any substrings. The substrings after splitting are returned inside an array.

Parameters

string $input

String to split into substrings based on *$separators.

boolean $ignoreEmpty

Choose whether to show empty strings, if any appear after splitting.

string *$separators

One or more strings to act as separators for splitting the string.

Returns

array

Array of substrings in between the strings listed in *$separators.

Examples

{
    a: split_on('ab\n\ncd',  `true`, `"\\n"`),
    b: split_on('ab\n\ncd', `false`, `"\\n"`),
    c: split_on('AabBaC', `true`, 'a', 'ab'),
    d: map(to_number(@, 'en-US'), split_on('[1, 2, 3, 4]', `true`, '[', ']', ', '))
}
{
  "a": ["ab", "cd"],
  "b": ["ab", "", "cd"],
  "c": ["A", "B", "C"],
  "d": [1, 2, 3, 4]
}