string.split([separator, [max_splits]]) → array
Split a string into substrings. With no arguments, will split on whitespace; when called with a string as the first argument, will split using that string as a separator. A maximum number of splits can also be specified. (To specify max_splits
while still splitting on whitespace, use null
as the separator argument.)
Mimics the behavior of Python’s string.split
in edge cases, except for splitting on the empty string, which instead produces an array of single-character strings.
Example: Split on whitespace.
r.expr("foo bar bax").split().run(conn);
Result:
["foo", "bar", "bax"]
Example: Split the entries in a CSV file.
r.expr("12,37,,22,").split(",").run(conn);
Result:
["12", "37", "", "22", ""]
Example: Split a string into characters.
r.expr("mlucy").split("").run(conn);
Result:
["m", "l", "u", "c", "y"]
Example: Split the entries in a CSV file, but only at most 3 times.
r.expr("12,37,,22,").split(",", 3).run(conn);
Result:
["12", "37", "", "22,"]
Example: Split on whitespace at most once (i.e. get the first word).
r.expr("foo bar bax").split(null, 1).run(conn);
Result:
["foo", "bar bax"]
Couldn't find what you were looking for?
© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/java/split/