Page 1 of 1

Open file for utf-8 write

Posted: Sat May 07, 2016 11:05 am
by guillem
I was trying to follow the instructions here: https://livecode.com/examining-unicode- ... ting-text/

But LC won't accept this line:

Code: Select all

open file tFile for utf-8 text write 
The card script gets a red dot when I apply it, but no error is shown.

Any ideas?

Re: Open file for utf-8 write

Posted: Sun May 08, 2016 12:21 am
by MaxV
Unicode is now integrated in livecode, so just write with your preferred keyboard and chars and all go ok.
Example:

Code: Select all

put "çòèù§ éà" into URL "file://myFile.txt"

Re: Open file for utf-8 write

Posted: Mon May 09, 2016 9:07 am
by guillem
Just for the record, in case somebody gets stuck with the same thing as me, the blog post missed the quotes. With "UTF-8" instead of UTF-8 it works.

I will try MaxV's solution, though. I didn't even think about that possibility, thanks!

Re: Open file for utf-8 write

Posted: Tue May 10, 2016 8:59 am
by guillem
Just tried omitting the UFT-8 altogether, but apparently it still is needed.

With

Code: Select all

open file tFile for "UTF-8" text write
I get Ενυδρίδα in the file. With

Code: Select all

open file tFile for text write
i get a row of interrogation marks.

As for the original problem, I guess it was the missing quotes all along. I don't know if someone could correct the blog entry for anybody else running into the same problem?

Re: Open file for utf-8 write

Posted: Tue May 10, 2016 12:24 pm
by MaxV
I tried this code:
########CODE#######
on mouseUp
set itemDel to "/"
set the defaultFolder to item 1 to -2 of (the effective fileName of this stack)
put the defaultFolder into temp
put temp
put "àòèéù" into URL ("binfile:" & temp & "/test.txt")
end mouseUp
#####END OF CODE#####

With Livecode 7.1.2 tested on windows: all ok
With Livecode 7.1.2 tested on Linux: all ok

However if the system is ISO, the standard output is ISO.

Re: Open file for utf-8 write

Posted: Tue May 10, 2016 12:39 pm
by MaxV
When you open the file with the editor, change editor characters encoding. Probably the problem is this.

Re: Open file for utf-8 write

Posted: Wed May 11, 2016 6:47 am
by guillem
Hi MaxV thanks for investigating!

Actually with the UTF-8 wrapped in quotes there is no problem now with the open file - write to file approach, with "Ενυδρίδα" before I was meaning a silly example of good outcome, sorry :oops:

Is your approach of put into url more recommended? I'm still on time of changing it.

Re: Open file for utf-8 write

Posted: Wed May 11, 2016 1:33 pm
by MaxV
What works with you is the recommended :D