Rebol 程式設計/語言特性/解析/使用特定分隔符進行分割
外觀
parse string none 表示式在以下情況下會失效:
- 你想要指定哪些字元應該被視為空格
- 你想要指定哪些字元應該被視為分隔符
- 你不想對引號進行特殊處理
- 你需要其他非簡單的分割方式
這些示例展示瞭如何影響 PARSE 函式處理空格的方式,或者如何使用特定分隔符來代替預設分隔符。
parse/all "only common delimiters; split the text, now" none ; == ["only common delimiters" " split the text" " now"]
如果你有不同的分隔符,你可以向 PARSE 提供包含你的分隔符的字串規則。
parse "red#blue#green" "#" ; == ["red" "blue" "green"]
parse/all "red blue^-green" " " ; == ["red" "blue^-green"]
parse "red#blue*green" "#*" ; == ["red" "blue" "green"]
請注意,分隔符字串中字元的順序並不重要。