Rebol Programming/Language Features/Parse/Simple splitting
String parsing involves simple splitting:
parse "this is a string" none ; == ["this" "is" "a" "string"]
By providing NONE as the PARSE rule, we are asking PARSE to break a string into a block of string(s) based on whitespace:
whitespace: charset [#"^A" - #" " "^(7F)^(A0)"]
and common delimiters:
common-delimiter: charset ",;"
To facilitate CSV splitting, quotation marks are handled specially (see the CSV example).
Examples
editEmpty string
editparse "" none ; == []
No delimiters in the input string
editparse "redbluegreen" none ; == ["redbluegreen"]
Space
editparse "red blue green" none ; == ["red" "blue" "green"]
Comma
editparse "red,blue,green" none ; == ["red" "blue" "green"]
Tab
editparse "red^-blue^-green" none ; == ["red" "blue" "green"]
Semicolon
editparse "red;blue;green" none ; == ["red" "blue" "green"]
Newline
editstring: { red blue green } parse string none ; == ["red" "blue" "green"]
Leading and trailing whitespaces are ignored
editparse " 1 " none ; == ["1"]
A sequence of whitespaces is equivalent to one whitespace
editparse "1 2" none ; == ["1" "2"]
Leading common delimiter delimits an empty substring
editparse ",1" none ; == ["" "1"]
One trailing common delimiter is ignored
editparse "1," none ; == ["1"]
A sequence of common delimiters delimits empty substrings between them
editparse "1,,2" none ; == ["1" "" "2"]
CSV
editparse {"red","blue","green"} none ; == ["red" "blue" "green"]