split_by_string

SinceVersion 1.2.2

description

Syntax

ARRAY<STRING> split_by_string(STRING s, STRING separator) 将字符串拆分为由字符串分隔的子字符串。它使用多个字符的常量字符串分隔符作为分隔符。如果字符串分隔符为空,它将字符串拆分为单个字符数组。

Arguments

separator — 分隔符是一个字符串,是用来分割的标志字符. 类型: String

s — 需要分割的字符串. 类型: String

Returned value(s)

返回一个包含子字符串的数组. 以下情况会返回空的子字符串:

需要分割的字符串的首尾是分隔符;

多个分隔符连续出现;

需要分割的字符串为空,而分隔符不为空.

Type: Array(String)

notice

仅支持向量化引擎中使用

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