Wednesday, March 29, 2017

#1 2005-10-21 07:38:43 am

julifos
Administrator
From: Malasaña, Madrid
Registered: 2002-11-20
Posts: 2014

Can I read/write text as UTF-8?

Yes. You can append a little "as «class utf8»" to your read-write commands and you are done.

Applescript:

set f to (open for access file x)
set eof of f to 0 --> empty file contents if needed
write "foo" to f as «class utf8»
close access f

If you need this file into a text editor, we would recommend adding a little flag to the file, so the text editor recognizes this is a utf-8 encoded file:

Applescript:

set f to (open for access file x)
set eof of f to 0 --> empty file contents if needed
--> now write the flag
write ((ASCII character 239) & (ASCII character 187) & (ASCII character 191)) to f --> not as «class utf8»
--> now write the data
write "foo" to f as «class utf8»
close access f

Reading is very similar:

Applescript:

read file x as «class utf8»

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.072 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)