Re: Coercing Styled Text to Text
Re: Coercing Styled Text to Text
- Subject: Re: Coercing Styled Text to Text
- From: Nigel Garvey <email@hidden>
- Date: Fri, 15 Jun 2001 11:27:43 +0100
Ehsan Saffari wrote on Thu, 14 Jun 2001 02:55:58 -0600:
>
On Wed, 13 Jun 2001 17:24:46 +0100, Nigel Garvey
>
<email@hidden> wrote:
>
>It was just a fast way that Jeff Baumann (I think) discovered to convert
>
>styled text into plain text. Obviously it would obviously be nicer if
>
>there were a more direct coercion. More recently, there's been Richard
>
>23's method, which I carelessly forgot to mention in my previous post:
>
>
>
> on error message
>
> set message to <<class ktxt>> of (message as record)
>
>
>
>('<<' and '>>' are of course the single characters produced on
>
>English-language keyboards by typing option-"\" and shift-option-"\"
>
>respectively.)
>
>
or a slightly differnt variation
>
>
set plainTxt to item 1 of (((stylTextObj) as record) as list)
... or indeed:
set plainTxt to rest of reverse of (((stylTextObj) as record) as list)
as string
;-)
Seriously though, I have mixed feelings about using numbered items of
lists coerced from records. The theory is that the labels in a record
aren't in any particular order. (ASLG: "A value of class Record is an
unordered collection of properties.") On the other hand, they usually
*are* in a particular order immediately after they're created. Does
anyone else have any views about this?
The other item in the list is a <<data>> object which is not coercible to
string, so you could in fact coerce the list instead of getting the
string item:
set plainTxt to stylTextObj as record as list as string
However, this still makes an intermediate list when all you really need
to do is to extract the string directly from the record.
NG