Re: Capturing parts of text string
Re: Capturing parts of text string
- Subject: Re: Capturing parts of text string
- From: "Patrick Collins" <email@hidden>
- Date: Sun, 3 Jul 2005 21:24:07 -0700 (PDT)
- Organization: Collinator Studios
Hi,
Thanks for the reply...
using option #1, i get:
Can't get text from word 1 of text 11 thru -1 of "Northbrook, IL 60062"
to word -2 of text 11 thru -1 of "Northbrook, IL 60062" of ", IL 60062".
using option #2, I get:
Can't get text from word 1 of item 2 of {"Northbrook", " IL 60062"} to
word -2 of item 2 of {"Northbrook", " IL 60062"} of " IL 60062".
... This script is extracting the contents of an html message in
mail.app by:
tell application "Mail"
set theseMessages to selection
set thisMessage to item 1 of theseMessages
set myTexted to (content of thisMessage) as string
end tell
set myText to myTexted as string
repeat with y in paragraphs of myText
... from there, we get to the part where it uses your routines.. if you
have any ideas why im getting these errors, that would be wonderful to
know... Does it have to do with the fact that Las Vegas was 2 words and
Northbrook is one?
-p
kai wrote on 7/3/05, 8:49 PM:
>
> On Monday, July 4, 2005, at 03:45 am, Patrick Collins wrote:
>
> > Just curious if I have a string:
> >
> > set x to "Las Vegas, Nevada 89102"
> >
> > how is the best way to extract the city, state, and zip into their own
> > strings?
> >
> > is the answer delimiters, or to use offsets of ", " and " "?
>
> You could go for either, Patrick. (Offset is slightly briefer, and TIDs
> can be faster on long strings - although that doesn't appear to be a
> huge issue here.) Rather than locate spaces, I'd probably just use the
> string elements 'word' and 'text' to help clean up the whole thing:
>
> --------------------
>
> on locationAsList(l)
> set o to (offset of "," in l)
> tell l to {text 1 thru (o - 1)} & (text o thru -1)'s {text from
> word 1
> to word -2, word -1}
> end locationAsList
>
> set x to "Las Vegas, Nevada 89102"
> set {city, state, zip} to locationAsList(x)
>
> --------------------
>
> on locationAsList(l)
> set d to text item delimiters
> set text item delimiters to ","
> tell l's text items to set l to {item 1} & item 2's {text from word 1
> to word -2, word -1}
> set text item delimiters to d
> l
> end locationAsList
>
> set x to "Las Vegas, Nevada 89102"
> set {city, state, zip} to locationAsList(x)
>
> --------------------
>
> -- results (from either method):
>
> city --> "Las Vegas"
> state --> "Nevada"
> zip --> "89102"
>
> ---
> kai
>
_______________________________________________
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