Is there a way to parse/all with '|' and ignore double or triple quotes?

Started by JackKort on 13-Mar-2018/12:24:10-7:00
I get long strings from an external source that are pipe-delimited; some of the fields can contain 2 or even 3 double quotes in a row, and parse/all is still seeing these as empty field boundaries. For example: >>tmp: {a|bc|"d,e"|""something"more"|g} >> parse/all tmp {|} == ["a" "bc" "d,e" "" {something"more"} "g"] what I *want* is just breaks on the pipes: ["a" "bc" "d,e" {""something"more"} "g"] Is there a way to do that with parse? Many thanks in advance!
Simple string splitting does not help here, but you can roll your own. >> out: copy [] parse/all tmp [any [copy val to "|" (append out val) skip ] copy val to end (append out val)] == true >> out == ["a" "bc" {"d,e"} {""something"more"} "g"]
P.S. depending on your version, if your last element is a delimiter, you'll get none or an empty string as the last element.
Wow! Seems to work great, and very concise. Thank you very much, Ingo!

Reply

Replies are rate limited to reduce abuse.