• 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
Re: Parsing quoted text
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Parsing quoted text


  • Subject: Re: Parsing quoted text
  • From: Yvan KOENIG <email@hidden>
  • Date: Tue, 26 Sep 2006 08:15:55 +0200


Le 26 sept. 2006 à 00:14, T&B a écrit :


Hi Yvan,

Here is a draft which seems to do the trick.

set textBlock to "item1  item2    'item 3'  [item 4]"
set delimiter to " "
set quotePairList to {{quote, quote}, {"'", "'"}, {"[", "]"}} --

set textBlock to normalize(textBlock, quotePairList)

set liste to spaces2space(textBlock)

Thanks for the thoughtful and quick response. When I try your script, I get the result:

{"item1", "item2", "'item 3'", "[item 4]"}

But it should be:

{"item1", "item2", "item 3", "item 4"}


I read too fast your question.
The required changes were short:

property sticky : ASCII character (202)
set textBlock to "item1  item2    'item 3'  [item 4]"
set delimiter to " "
set quotePairList to {{quote, quote}, {"'", "'"}, {"[", "]"}} --


set textBlock to normalize(textBlock, quotePairList)

set liste to spaces2space(textBlock)

on spaces2space(T)
repeat while T contains "  "
set AppleScript's text item delimiters to "  "
set lt to text items of T
set AppleScript's text item delimiters to space
set T to lt as text
end repeat
set lt to text items of T
set AppleScript's text item delimiters to ""
return lt
end spaces2space

on normalize(T, L)
set k to count of L
repeat with ba in L
set {b, a} to ba
if b is in T then
set AppleScript's text item delimiters to b
set lt to text items of T
if b = a then
repeat with i from 2 to ((count of lt) - 1) by 2
set lti to lt's item i
if lti contains space then
set AppleScript's text item delimiters to space
set lt3 to text items of lti
set AppleScript's text item delimiters to sticky
set lt's item i to lt3 as text
end if -- contains space
end repeat -- i
else
repeat with i from 2 to (count of lt)
set lti to lt's item i
if lti contains a then
set AppleScript's text item delimiters to a
set lt2 to text items of lti
if lt2's item 1 contains space then
set AppleScript's text item delimiters to space
set lt3 to text items of lt2's item 1
set AppleScript's text item delimiters to sticky
set lt2's item 1 to lt3 as text
end if -- contains space
set AppleScript's text item delimiters to "" --  was a
set lt's item i to lt2 as text
end if
end repeat -- i
end if -- b=a
set AppleScript's text item delimiters to "" -- was b
set T to lt as text
end if -- b is in T
end repeat -- ba
set AppleScript's text item delimiters to ""
return T
end normalize

Yvan KOENIG
 _______________________________________________
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

References: 
 >Parsing quoted text (From: T&B <email@hidden>)
 >Re: Parsing quoted text (From: Yvan KOENIG <email@hidden>)
 >Re: Parsing quoted text (From: T&B <email@hidden>)

  • Prev by Date: Re: Re: Excel Find an empty cell
  • Next by Date: Re: Parsing quoted text
  • Previous by thread: Re: Parsing quoted text
  • Next by thread: Re: Parsing quoted text
  • Index(es):
    • Date
    • Thread