Open file for utf-8 write

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
guillem
Posts: 13
Joined: Tue Apr 12, 2016 7:36 pm

Open file for utf-8 write

Post by guillem » Sat May 07, 2016 11:05 am

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?
LC8, OSX 10.9.5 (Mavericks)

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Open file for utf-8 write

Post by MaxV » Sun May 08, 2016 12:21 am

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"
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

guillem
Posts: 13
Joined: Tue Apr 12, 2016 7:36 pm

Re: Open file for utf-8 write

Post by guillem » Mon May 09, 2016 9:07 am

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!
LC8, OSX 10.9.5 (Mavericks)

guillem
Posts: 13
Joined: Tue Apr 12, 2016 7:36 pm

Re: Open file for utf-8 write

Post by guillem » Tue May 10, 2016 8:59 am

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?
LC8, OSX 10.9.5 (Mavericks)

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Open file for utf-8 write

Post by MaxV » Tue May 10, 2016 12:24 pm

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.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Open file for utf-8 write

Post by MaxV » Tue May 10, 2016 12:39 pm

When you open the file with the editor, change editor characters encoding. Probably the problem is this.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

guillem
Posts: 13
Joined: Tue Apr 12, 2016 7:36 pm

Re: Open file for utf-8 write

Post by guillem » Wed May 11, 2016 6:47 am

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.
LC8, OSX 10.9.5 (Mavericks)

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Open file for utf-8 write

Post by MaxV » Wed May 11, 2016 1:33 pm

What works with you is the recommended :D
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply