Re: Separating Text
Re: Separating Text
- Subject: Re: Separating Text
- From: Jolly Roger <email@hidden>
- Date: Mon, 19 Nov 2001 12:51:45 -0600
On 11/18/2001 6:55 PM, "JRyan" <email@hidden> wrote:
>
My latest problem is setting my comment variable to only part of the
>
comment text (only up to some special character) and then my keyword
>
variables to the remaining words... I seem to be having difficulty
>
reading and copying only parts of the text.. I think I can do this
>
by writing the comment to a file and then reading the file with the
>
'until' and 'from' parameters, but is there a way I can do this and
>
have the script stay self contained?
You might look into doing something like this (insert your own special
character in place of mine below):
-- begin script
property sometext : "some text here with a special character here< and some
more text following that."
set saveDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"<"}
set textItems to the text items of sometext
set AppleScript's text item delimiters to saveDelims
log item 1 of textItems
-- end script
The above script uses an efficient method to parse text using AppleScript.
Using Applecript's text item delimiters, it splits the text into two (or
more) pieces, using a special character as a delimiter. Wherever the
special character appears in the text, the text is split at that point, and
the next item starts. This is a powerful (and somewhat hidden) feature of
the AppleScript language.
HTH
JR