Page 1 of 1

Convert UTF-16 to UTF-8

Posted: Wed Mar 25, 2015 9:26 am
by bergsy
Hi,

I see a lot of examples for converting UTF-8 to UTF-16 but not the other way around. I am editing the XML in a MS Word document, which expects UTF-8. I have tried changing the encoding in the XML to use UTF-16 but it doesn't work (MS just seems to ignore that direction).

I have a word "Équipe" that I am putting into the Word XML. I have also created a basic document to see what Word does in encoding the word. The letter "É" is encoded (hex) as C3 89, whereas the UTF-16 value is (hex) C9. I checked other characters and it seems the accented characters are represented in Word as C3 and hex 40 less than the UTF-16 value.

Is there any code that converts the UTF-16 from Livecode into the UTF-8 I need for MS Word?

Thanks for any assistance

Cheers

Bergsy

Re: Convert UTF-16 to UTF-8

Posted: Wed Mar 25, 2015 7:18 pm
by jacque
If you're using LC 7.x the "textEncode" command is the easiest way. From the dictionary:

put textEncode(field "output","UTF-8") into tOutput

Re: Convert UTF-16 to UTF-8

Posted: Thu Mar 26, 2015 6:35 am
by bergsy
Hi Jacque,

That did the trick - thanks :)

Bergsy