GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Close
  • FAQ
  • Docs
  • API
  • Community
  • Blog
  • Accessing ReQL
  • r
  • connect
  • close
  • reconnect
  • use
  • run
  • changes

This view

  • Original page
  • New address

GeezerVison is showing rethinkdb.com — ReQL command reference - RethinkDB


▲ Back to top

Command syntax

string.split([separator, [max_splits]]) → array

Description

Splits a string into substrings. Splits on whitespace when called with no arguments. When called with a separator, splits on that separator. When called with a separator and a maximum number of splits, splits on that separator at most max_splits times. (Can be called with null as the separator if you want to split on whitespace while still specifying max_splits.)

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, callback)

Result:

["foo", "bar", "bax"]

Example: Split the entries in a CSV file.

r.expr("12,37,,22,").split(",").run(conn, callback)

Result:

["12", "37", "", "22", ""]

Example: Split a string into characters.

r.expr("mlucy").split("").run(conn, callback)

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, callback)

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, callback)

Result:

["foo", "bar bax"]

Related commands

  • upcase
  • downcase
  • match

Get more help

Couldn't find what you were looking for?

  • Ask a question on Stack Overflow
  • Chat with us and our community on Slack
  • Talk to the team on IRC on #[email protected] — via Webchat
  • Ping @rethinkdb on Twitter
  • Post an issue on the documentation issue tracker on GitHub

Contribute: edit this page or open an issue

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.