Writing to file in utf-8

Mark Schonewille m.schonewille at economy-x-talk.com
Wed Sep 3 07:41:53 EDT 2014


Hi Jbv,

Lots of information is missing. First of all, which version of LiveCode 
are you using? There are quite a few differences between 5, 6 and 7.

You provide one line of syntax, but it isn't clear where the contents of 
the it variable comes from, e.g. from a file or a field.

It isn't clear if the files are 100% UTF8 or e.g. are they Latin1 or 
MacRoman encoded XML files with some UTF8 encoded strings? (Not very 
likely to happen, but perhaps something similar is going on).

Generally, if you import a UTF8 file into a field, you do this:

put url ("binfile:" & myUrl) into myData
put uniEncode(myData,"UTF8") into myData
set the unicodeText of fld 1 to myData

and to export you use

put the unicodeText of fld 1 into myData
put uniDecode(myData,"UTF8") into myData
put myData into url ("binfile:" & myUrl)

This should work with all versions, although LiveCode 7 will have 
different ways to work with unicode text.

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

Installer Maker for LiveCode:
http://qery.us/468

Buy my new book "Programming LiveCode for the Real Beginner" 
http://qery.us/3fi

LiveCode on Facebook:
https://www.facebook.com/groups/runrev/

On 9/3/2014 13:28, jbv at souslelogo.com wrote:
> Hi list
>
> I have a script that accumulates successive strings into a file.
> Each string comes from utf-8 text files and contains french
> characters with accents like "é à ô".
> After processing in the script, those strings get accumulated
> in other txt files. I need these second serie of files to be in
> utf-8 format too.
> So I use the following code (found in this LC lesson :
> http://lessons.runrev.com/m/4071/l/20441-unicode )
>
> put (unidecode(it,"utf8") & return) after url tPath
>
> but when I open the file tPath in a text editor, everything is
> replaced by chinese chars...
>
> What am I missing ?
> Thanks in advance.
> jbv





More information about the use-livecode mailing list