Parsing quoted text
Parsing quoted text
- Subject: Parsing quoted text
- From: T&B <email@hidden>
- Date: Tue, 26 Sep 2006 00:17:24 +1000
Hi all,
Thanks for the lively discussion on CSV (comma separated values) parsing. Now I have a similar question, in case someone has a solution.
I want to be able to parse a string into a list, given a delimiter and a list of possible quotes.
For instance, this:
item1 item2 'item 3' 'item 4' [item 5] "item[6]" 'item "7"'
parsed using a delimiter of: a space
and a list of quote pairs: "" '' []
Would give:
{"item1", "item2", "item 3", "item 4", "item 5", "item[6]", "item \"7\""}
Furthermore, it would be great to have an option to treat any amount of white space as a single delimiter. So, for example:
item1 item2 'item 3'
would still give:
{"item1", "item2", "item 3"}
The function would be something like this:
on ParseQuotedText of textBlock between delimiter out of quotePairList
-- Parsing routine here
return unquotedList
end ParseQuotedText
So that:
set textBlock to "item1 item2 'item 3'"
set delimiter to " "
set quotePairList to {{quote,quote},{"'","'"},{"[","]"}}
ParseQuotedText of textBlock between delimiter out of quotePairList
would give:
-> {"item1", "item2", "item 3"}
Thanks,
Tom
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden