Re: strings and strings (was Don't get it.)
Re: strings and strings (was Don't get it.)
- Subject: Re: strings and strings (was Don't get it.)
- From: Peter Waibel <email@hidden>
- Date: Wed, 20 Dec 2006 13:16:55 +0100
I've forgotten the details, but IIRC a string can contain 'pure'
characters,
or also additional formatting information. ...
Somewhere I found the handler "AsText".
As far as I know this handler is from Arthur Knapp.
I should point out that you really shouldn't have to use this
trick. We consider software that requires it to have a bug which
should be corrected. If you know of any offenders [1], please let
us know who they are.
I had some problems when I had to parse command files with key value
pairs.
As long as the command file had 7 bit encoding there was no problem
at all.
But as the encoding changed to Unicode applescript did no more coerce
the text "true", "false" to boolean!
I thing that a character sequence "false" and "true"
should allways coerce to a valid boolean
or should never coerce at all!
(see code snippets below)
Meanwhile the AsText() handler is very handy.
Peter
----------------------------------------------------------------------
set myBoolStr to "false" as string
set myBoolStr to "false" as text
set myBoolStr to "false" as styled text
set myBoolStr to "false" as Unicode text
set myBoolStr to "false" as international text
-- return class of myBoolStr
--> string - string
--> text - string
--> styled text - string
--> Unicode text - Unicode text
--> international text - string
set myBool to myBoolStr as boolean
-- error for: international text, Unicode text, styled text
set myBool to AsText(myBoolStr) as boolean
-- no error
on AsText(str)
--coerce Unicode or other text to styled string to plain text
try
return (((str as string) as record)'s «class ktxt»)
end try
return str
end AsText
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden