splitString function
Syntax
string[] splitString(inputString, delimiter)
Parameters
- inputString (string)
String to be split into separate substrings. - delimiter (string)
Delimiter string that separates substrings. The delimiter may also be specified as a regular expression using a preceding '$' as the first character of the delimiter string. A split by '$' must be expressed by a regular expression (see example below).
Returns
Array of substrings of given input string.
Description
Splits a string into several substrings separated by a given delimiter string.
The size of the returned array is limited. It can be configured in the Procedural Runtime preferences (Default: 100000).
Related
- substring function
- readTextFile function
- fileSearch / filesSearch function
- size function
- Array types operators
- findFirst function
Examples
Delimiter string
Input | Delimiter | CGA | Result |
---|---|---|---|
a.b.c |
. |
splitString("a.b.c", ".") |
(3)[a,b,c] |
.b. |
. |
splitString(".b.", ".") |
(3)[,b,] |
a.b↵ |
\n |
splitString("a.b\nc.d", "\n") |
(2)[a.b,c.d] |
a\b\c |
\ |
splitString("a\\b\\c", "\\") |
(3)[a,b,c] |
abc |
empty | splitString("abc", "") |
(5)[,a,b,c,] |
Regular expression
Input | Reg. expr. | CGA | Result |
---|---|---|---|
a;b;c |
; |
splitString("a;b;c", "$;") |
(3)[a,b,c] |
a.b.c |
\. |
splitString("a.b.c", "$\\.") |
(3)[a,b,c] |
a→ → b→ c |
\t+ |
splitString("a\t\tb\tc", "$\t+") |
(3)[a,b,c] |
a b c |
\s+ |
splitString("a b c", "$\\s+") |
(3)[a,b,c] |
a$b$c |
\$ |
splitString("a$b$c", "$\\$") |
(3)[a,b,c] |
abc |
\B |
splitString("abc", "$\\B") |
(3)[a,b,c] |
abacba |
(?<=a)b(?=a) |
splitString("abacba", "$(?<=a)b(?=a)") |
(2)[a,acba] |
Parsing files
// table // a;b↵ // c;d↵ const file = readTextFile("table.txt") const rows = splitString(file, "\n") // [a;b,c;d,] const headers = splitString(rows[0], ";") // [a,b]
Copyright ©2008-2024 Esri R&D Center Zurich. All rights reserved.