Re: TID (Text Item Delimiters)
Re: TID (Text Item Delimiters)
- Subject: Re: TID (Text Item Delimiters)
- From: Andrew Oliver <email@hidden>
- Date: Fri, 30 May 2003 10:35:39 -0700
Your script does exactly what I expect it to do, but I'm guessing that isn't
what you expect it to do. :)
First, setting AppleScript's TIDs is not additive. In the first line of
shortenMonth you set the TIDs to " ". On the next line you *replace* the
space with a null string, then you *replace* them again with a "-".
So by the time the actual starts to run, TIDs is a hyphen. The space and
null are history.
Secondly, once you've set the TIDS, you then need to ask for "text item n"
to get the nth delimited string. Just asking for "item 2" of a string will
get you the second CHARACTER, not the second delimited string.
Consider:
set readData to " 2 7 -June-2003"
set AppleScript's text item delimiters to "-"
display dialog (item 2 of readData) --> "2"
display dialog (text item 2 of readData) --> "June"
Finally, once you're past that, you then get "characters 1 through 3 of
readData". 'characters' ignores text item delimiters altogether and returns
the specified character range, in this case " 2 "
In short, you need to use 'text items' to get parts of a delimited string
based on the last-defined 'text item delimiters'
Hope that helps get you where you want to go.
Andrew
:)
On 5/30/03 9:48 AM, "Robert Poland" <email@hidden> wrote:
>
Hi,
>
>
Speaking of TIDs, Why doesn't the following remove spaces? and why
>
are the letters items and not words?
>
>
set readData to " 2 7 -June-2003"
>
my shortenMonth(readData)
>
display dialog ">" & result & "<" as string -- arrows for clarity
>
>
>
on shortenMonth(readData) -- set month to first 3 characters
>
set AppleScript's text item delimiters to " " -- set TID to space
>
set AppleScript's text item delimiters to "" -- remove spaces
>
set AppleScript's text item delimiters to "-" -- seperate
>
into three words
>
set theMonth to item 2 of readData
>
display dialog theMonth as string
>
set result to (characters 1 thru 3 of readData)
>
set readData to (result)
>
set AppleScript's text item delimiters to ""
>
return {readData}
>
end shortenMonth
>
>
TIA,
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.