Rebol 编程/语言特性/解析/简单拆分
外观
字符串解析涉及简单拆分
parse "this is a string" none ; == ["this" "is" "a" "string"]
通过提供 NONE 作为 PARSE 规则,我们要求 PARSE 基于空格将字符串拆分为字符串块
whitespace: charset [#"^A" - #" " "^(7F)^(A0)"]
和公共分隔符
common-delimiter: charset ",;"
为了便于 CSV 拆分,引号将被特殊处理(参见 CSV 示例)。
parse "" none ; == []
parse "redbluegreen" none ; == ["redbluegreen"]
parse "red blue green" none ; == ["red" "blue" "green"]
parse "red,blue,green" none ; == ["red" "blue" "green"]
parse "red^-blue^-green" none ; == ["red" "blue" "green"]
parse "red;blue;green" none ; == ["red" "blue" "green"]
string: { red blue green } parse string none ; == ["red" "blue" "green"]
parse " 1 " none ; == ["1"]
parse "1 2" none ; == ["1" "2"]
parse ",1" none ; == ["" "1"]
parse "1," none ; == ["1"]
parse "1,,2" none ; == ["1" "" "2"]
parse {"red","blue","green"} none ; == ["red" "blue" "green"]