Re: Separating Text
Re: Separating Text
- Subject: Re: Separating Text
- From: Mr Tea <email@hidden>
- Date: Mon, 19 Nov 2001 16:32:35 +0000
This from JRyan - dated 19/11/01 12.55 am:
>
My latest problem is setting my comment variable to only part of the
>
comment text (only up to some special character)
If your 'special character' is used only once in the comment, this is a
doddle. You need to reset AppleScript's default text item delimiters...
A text item delimiter is that which separates one text item from the next.
Usually this is set to '"", which equates to the space that separates each
letter, a space which effectively contains nothing at all. (This is not the
same as the 'space' character that is used to separate words - that kind of
space is also a 'text item')
So, if you ask AppleScript to give you every text item of "Hello World", it
will return a list containing 11 individual strings, each containing one
letter or space character.
If your Finder comment is something like "Nice legs*shame about the face",
you could do something like this...
set myComment to "Nice legs*shame about the face"
copy AppleScript's text item delimiters to oldTIDs
set AppleScript's text item delimiters to "*"
copy text item 1 of myComment to partOne
copy text item 2 of myComment to partTwo
set AppleScript's text item delimiters to oldTIDs
display dialog partOne -- "Nice legs"
display dialog partTwo -- "shame about the face"
Note that the script resets the delimiters to their previous (default)
value. As I understand it, you should always do this when messing around
with the TIDs, otherwise BAD THINGS WILL HAPPEN!
HTH
Mr Tea
--