Convert UTF-16 to UTF-8

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bergsy
Posts: 45
Joined: Mon Oct 28, 2013 10:51 pm

Convert UTF-16 to UTF-8

Post by bergsy » Wed Mar 25, 2015 9:26 am

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Convert UTF-16 to UTF-8

Post by jacque » Wed Mar 25, 2015 7:18 pm

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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bergsy
Posts: 45
Joined: Mon Oct 28, 2013 10:51 pm

Re: Convert UTF-16 to UTF-8

Post by bergsy » Thu Mar 26, 2015 6:35 am

Hi Jacque,

That did the trick - thanks :)

Bergsy

Post Reply