Re: Length of string as UTF-8
Re: Length of string as UTF-8
- Subject: Re: Length of string as UTF-8
- From: Axel Luttgens <email@hidden>
- Date: Sun, 06 Aug 2006 16:24:33 +0200
On 6/08/06 11:29, Tom Robinson wrote:
Hi people,
Is there a way to get the length of a Unicode string as it would be
represented in UTF-8?
I have an AppleScript which uses Unicode strings, which I then write
to a file. I need to keep the files under 4096 bytes for displaying
on an iPod.
e.g.:
set a to "don’t" as Unicode text -- that's a right single curly quote
log length of a -- This returns 5, but underlying AS it's probably 10
(the quote being U2019)
log length of (a as «class utf8») -- This still returns 5, but I'd
like something similar to this which returns 7 (the quote being UTF-8
e2 80 99)
Thoughts?
Well, one thought... ;-)
set a to "don’t"
set a to quoted form of a
(do shell script "echo -n " & a & " | wc -c") as number
Sure not the nicest nor the most efficient way.
But perhaps something to start with, until someone else comes with a
better way...
HTH,
Axel
PS: by removing the parentheses from the line with the "do shell script"
command, I get here:
«data nmbr2020202020202037»
It's true that in the above, wc outputs seven spaces followed by digit
7, hence the hex data. But why such a partial evaluation as a number?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden