Need Help Parsing Clojure Strings
I have a web application that returns data that is pipe-delimited and looks like this: AT|1 Kenilworth Rd||Soapville|ZA|99901-7505|Option value=A == Normal street matchOption value=T == ZIP+4 corrected|013|C065| What I want to do is take the zip-zip4 field, split the zip and zip 4 apart, and add them as separate fields right after state ZA. I want to do some other things too (like remove from Option value... through 013), but that's the next step. This function (defn rearrange-accumail-seq Fixes up AccuMail sequence, so we have the right data, and it's in the correct order. [in-str] (let [s1 (cstr/split in-str #^\w*\|\w*\|\w*\|\w*\|)] s1)) does not do what I expect it to. That is I cannot find first and next in the vector of splits returned. [AT|1 Kenilworth Rd||Soapville|ZA|99901-7505|Option value=A == Normal street matchOption value=T == ZIP+4 corrected|013|C065|] Should I be using Java string parsing directly, or am I missing something basic? Thanks. cmn -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Need Help Parsing Clojure Strings
Do you want something like: (vec (.split some-string \\|)) (vec (.split AT|1 Kenilworth Rd||Soapville|ZA|99901-7505|Option value=A == Normal street matchOption value=T == ZIP+4 corrected|013|C065| \\|)) = [AT 1 Kenilworth Rd Soapville ZA 99901-7505 Option value=A == Normal street matchOption value=T == ZIP+4 corrected 013 C065] -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Need Help Parsing Clojure Strings
octopusgrabbus octopusgrab...@gmail.com writes: Hi! What I want to do is take the zip-zip4 field, split the zip and zip 4 apart, and add them as separate fields right after state ZA. I want to do some other things too (like remove from Option value... through 013), but that's the next step. This function (defn rearrange-accumail-seq Fixes up AccuMail sequence, so we have the right data, and it's in the correct order. [in-str] (let [s1 (cstr/split in-str #^\w*\|\w*\|\w*\|\w*\|)] s1)) does not do what I expect it to. That is I cannot find first and next in the vector of splits returned. `split' expects a regex that matches the *separator*. (clojure.string/split foo|bar|baz #\|) == [foo bar baz] Then you can take the compontents of the resulting vector and shuffle them to your likings. Bye, Tassilo -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Need Help Parsing Clojure Strings
Thanks. I finally got part of my problem when I changed the regex to #\d\d\d\d\d-\d\d\d\d to match the zip-zip4, and when that disappeared, I realized what was going on. On Jul 25, 3:51 pm, Tassilo Horn tass...@member.fsf.org wrote: octopusgrabbus octopusgrab...@gmail.com writes: Hi! What I want to do is take the zip-zip4 field, split the zip and zip 4 apart, and add them as separate fields right after state ZA. I want to do some other things too (like remove from Option value... through 013), but that's the next step. This function (defn rearrange-accumail-seq Fixes up AccuMail sequence, so we have the right data, and it's in the correct order. [in-str] (let [s1 (cstr/split in-str #^\w*\|\w*\|\w*\|\w*\|)] s1)) does not do what I expect it to. That is I cannot find first and next in the vector of splits returned. `split' expects a regex that matches the *separator*. (clojure.string/split foo|bar|baz #\|) == [foo bar baz] Then you can take the compontents of the resulting vector and shuffle them to your likings. Bye, Tassilo -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Need Help Parsing Clojure Strings
Thanks for the suggestion. I will try this tomorrow and report back. On Jul 25, 3:46 pm, Islon Scherer islonsche...@gmail.com wrote: Do you want something like: (vec (.split some-string \\|)) (vec (.split AT|1 Kenilworth Rd||Soapville|ZA|99901-7505|Option value=A == Normal street matchOption value=T == ZIP+4 corrected|013|C065| \\|)) = [AT 1 Kenilworth Rd Soapville ZA 99901-7505 Option value=A == Normal street matchOption value=T == ZIP+4 corrected 013 C065] -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en