• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Parsing quoted text
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Parsing quoted text
      • From: Yvan KOENIG <email@hidden>
  • Prev by Date: Re: List MOM, et al.
  • Next by Date: Re: List MOM, et al.
  • Previous by thread: Find the Next open cell
  • Next by thread: Re: Parsing quoted text
  • Index(es):
    • Date
    • Thread