split_by_string

description

Syntax

ARRAY<STRING> split_by_string(STRING s, STRING separator)

Splits a string into substrings separated by a string. It uses a constant string separator of multiple characters as the separator. If the string separator is empty, it will split the string s into an array of single characters.

Arguments

separator — The separator. Type: String

s — The string to split. Type: String

Returned value(s)

Returns an array of selected substrings. Empty substrings may be selected when:

A non-empty separator occurs at the beginning or end of the string;

There are multiple consecutive separators;

The original string s is empty.

Type: Array(String)

example

  1. select split_by_string('a1b1c1d','1');
  2. +---------------------------------+
  3. | split_by_string('a1b1c1d', '1') |
  4. +---------------------------------+
  5. | ['a', 'b', 'c', 'd'] |
  6. +---------------------------------+
  7. select split_by_string(',,a,b,c,',',');
  8. +----------------------------------+
  9. | split_by_string(',,a,b,c,', ',') |
  10. +----------------------------------+
  11. | ['', '', 'a', 'b', 'c', ''] |
  12. +----------------------------------+
  13. SELECT split_by_string(NULL,',');
  14. +----------------------------+
  15. | split_by_string(NULL, ',') |
  16. +----------------------------+
  17. | NULL |
  18. +----------------------------+
  19. select split_by_string('a,b,c,abcde',',');
  20. +-------------------------------------+
  21. | split_by_string('a,b,c,abcde', ',') |
  22. +-------------------------------------+
  23. | ['a', 'b', 'c', 'abcde'] |
  24. +-------------------------------------+
  25. select split_by_string('1,,2,3,,4,5,,abcde', ',,');
  26. +---------------------------------------------+
  27. | split_by_string('1,,2,3,,4,5,,abcde', ',,') |
  28. +---------------------------------------------+
  29. | ['1', '2,3', '4,5', 'abcde'] |
  30. +---------------------------------------------+
  31. select split_by_string(',,,,',',,');
  32. +-------------------------------+
  33. | split_by_string(',,,,', ',,') |
  34. +-------------------------------+
  35. | ['', '', ''] |
  36. +-------------------------------+
  37. select split_by_string(',,a,,b,,c,,',',,');
  38. +--------------------------------------+
  39. | split_by_string(',,a,,b,,c,,', ',,') |
  40. +--------------------------------------+
  41. | ['', 'a', 'b', 'c', ''] |
  42. +--------------------------------------+

keywords

SPLIT_BY_STRING,SPLIT