Re: what the heck - text manipulation script
Re: what the heck - text manipulation script
- Subject: Re: what the heck - text manipulation script
- From: kai <email@hidden>
- Date: Tue, 18 Jul 2006 18:08:30 +0100
On 18 Jul 2006, at 15:52, Natalie Lambert wrote:
I'm trying to do some manipulating of some text. For
some reason I can't get exactly what I want out of
it.... Its driving me a little nuts. Is there some
rule I have forgotten about?????
set x to "OCT 05 @St. Louis" as text
set v to word 4 of x
return v
why does the result of this scipt = "St". I need
"@St." It always drops the @ and the period.....
The interpretation of what constitutes a word can differ depending on
context, Natalie. Certain characters may be regarded as individual
words - or nothing to do with a word at all. The rules can change
depending on whether adjacent characters are letters or numbers - and
there are even differences between plain and Unicode text. For example:
---------
set t to "chrysoberyl_1'23.4@cat's-eyes.com is a bogus e-mail address…"
{t's words, (t as Unicode text)'s words}
--> {{"chrysoberyl", "_", "1'23.4", "@", "cat's-eyes.com", "is", "a",
"bogus", "e-mail", "address"}, {"chrysoberyl_1", "23.4", "cat's",
"eyes", "com", "is", "a", "bogus", "e", "mail", "address"}}
---------
even if I start delimiting I get weird stuff
happening. what works on 10.2.8 (home) doesn't work
on 10.4.4 (work)
While there are numerous ways in which text can be parsed
(AppleScript's text item delimiters being one of them), the best
results are achieved when you can identify certain common
characteristics of the source text that might be used to delimit it
(tabs, spaces, carriage returns, line feeds, colons, semi-colons,
commas, etc.) - and then define some general parsing rule[s].
If, for instance, you're looking for some text starting with (and
including) a certain character and ending with (but excluding)
another character, you might - using text item delimiters - try
something like:
---------
to |get text| of t from s to e
if s is not in t then return "" (* or do something else *)
set {d, text item delimiters} to {text item delimiters, s}
set {t, text item delimiters} to {t's text from t's text item 2 to
end, e}
set {t, text item delimiters} to {t's text item 1, d}
s & t
end |get text|
set txt to "OCT 05 @St. Louis"
|get text| of txt from "@" to space
--> "@St."
---------
Something as specific as that could also be done, a little more
simply, using offset:
---------
to |get text| of t from s to e
if s is not in t then return "" (* or do something else *)
set t to t's text (offset of s in t) thru end
t's text 1 thru ((offset of e in t) - 1)
end |get text|
set txt to "OCT 05 @St. Louis"
|get text| of txt from "@" to space
--> "@St."
---------
If you're trying to do something else, then perhaps you could give us
some more precise information about the structure of the source text
and the general aims of the parsing process.
---
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