save text into UTF8 file

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
operoutka
Posts: 12
Joined: Tue Apr 04, 2006 6:50 am

save text into UTF8 file

Post by operoutka » Thu Jan 25, 2018 10:24 pm

Hi,
I don't be able to save right my text into UTF file. I use:

create field "Tmp"
put txtData into field "Tmp"
put uniDecode(the unicodeText of field "Tmp","UTF8") into txtData
put txtData into URL("file:" & theFileName)
delete field "Tmp"

my chars (Czech) are OK but if text is ": + TAB + x" where "x" is a number in txtData so in file is putting before number "cr". If "x" is not a number all is OK. What do I make wrong?

for example: in variable txtData is text:
my parameter 1: TAB false
my parameter 2: TAB 123

in file is text:
my parameter 1: TAB false
my parameter 2:
TAB 123

Txt "my parameter 2:
TAB 123" is wrong. It should be my parameter 2: TAB 123, but wrong is only if number is in line. I don' know what I do wrong.

I use Mac OS High Siera and LC 8.1.8 build 14052. Can me help anybody?

Kind Regards,

Oldrich

matthiasr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 190
Joined: Sat Apr 08, 2006 7:55 am
Location: Lübbecke, Germany
Contact:

Re: save text into UTF8 file

Post by matthiasr » Thu Jan 25, 2018 10:27 pm

Hi,
if i remember right you have to write the data as binfile.

So change line 4 of your sample script to
put txtData into URL("binfile:" & theFileName)

Regards,
Matthias

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: save text into UTF8 file

Post by Klaus » Thu Jan 25, 2018 10:46 pm

Hi Oldrich,

what Matthias said AND all these unicode related commands like "unicodetext" and "uniencode" etc. have been deprecated in version 7 ("Unicode, it just works!") of LC!

So this should do the trick:

Code: Select all

...
put textencode(the text of field "Tmp","UTF8") into txtData
put txtData into URL("binfile:" & theFileName)
...
Best

Klaus

operoutka
Posts: 12
Joined: Tue Apr 04, 2006 6:50 am

Re: save text into UTF8 file

Post by operoutka » Fri Jan 26, 2018 7:24 am

Hi,

thank for your answers-back but result is equal with my version instruction rows. If is there ":" + TAB + a number, then is in both these cases added cr before TAB and TAB + a number is on the next line. What can I try along? Me namely nothing else limps. :-(

Thank for next advice?

Oldrich

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: save text into UTF8 file

Post by SparkOut » Fri Jan 26, 2018 8:21 am

Can't check right now but look at whether your file needs or doesn't need a BOM (Byte Order Marker). Sounds like it might be needed for you.
It may be a big-endian v little-endian issue where your cr is marking the end of line, but displayed in the wrong order so appears to come before the line in your reader.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: save text into UTF8 file

Post by Klaus » Fri Jan 26, 2018 11:19 am

Big question is, what format is your txtData BEFORE you put it into fld TEMP?
Where does the data come from? Can you check if it looks correct in a field in LC?

operoutka
Posts: 12
Joined: Tue Apr 04, 2006 6:50 am

Re: save text into UTF8 file

Post by operoutka » Fri Jan 26, 2018 1:49 pm

Hi,

format of txtData I didn't addressed. In LC only I put text into variable txtData (for example: put cr & "my text 1:" & TAB & theParameter into txtData) and than I will it to save in file. It is all.

Text format in txtData I didn't addressed. I put text into variable and save to file without any address for text format.

Regards,
Oldrich

operoutka
Posts: 12
Joined: Tue Apr 04, 2006 6:50 am

Re: save text into UTF8 file

Post by operoutka » Fri Jan 26, 2018 1:51 pm

Hi,

If I look the text data in LC (variable txtData), so the the text data looks OK.

Regards,

Oldrich

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: save text into UTF8 file

Post by Klaus » Fri Jan 26, 2018 1:58 pm

What if you just leave out the step with the field, which is not neccessary actually?

Code: Select all

...
put textencode(txtData,"UTF8") into txtData
put txtData into URL("binfile:" & theFileName)
...

operoutka
Posts: 12
Joined: Tue Apr 04, 2006 6:50 am

Re: save text into UTF8 file

Post by operoutka » Fri Jan 26, 2018 7:12 pm

Hi,
I'm already tried this and result is equal. Czech chars (ěščřžýáíéůú and next chars) are OK and the lines where are not ":" + TAB + number are OK too.
variable = file
text note:+ TAB + "-" = text note: + TAB + "-"
text note 1:+ TAB + false = text note 1: + TAB + false
text note 2: + TAB + true = text note 1: + TAB + true
but
text note 3: + TAB + 5 = text note 3:
+ TAB + 5

I checked variable txtData in LC and there is OK too.

I don't know what with it? Open file and replace ":+TAB" +cr with ":" +TAB? I don't know, this is loss if it will work.

Regards
Oldrich

operoutka
Posts: 12
Joined: Tue Apr 04, 2006 6:50 am

Re: save text into UTF8 file

Post by operoutka » Fri Jan 26, 2018 10:44 pm

Hi,

thanks for help, now it is OK, all.
This problem was probably in my text file for button's Label. This file (text) I wrote in Mac (TextEdit.app) and Win (Notepad.exe) too and in the same file (only the one file).
Than, in LC I assembled text in variable txtData as:
put cr & the Label of button "theButton" & TAB & parameter after txtData
put cr & the Label of button "theButton1" & TAB & parameter1 after txtData
etc.
where the Label of button "theButton" was displayed as "xxxx:", but it wasn't the truth. There was any other char not displayed in button's label and in variable txtData in LC(?) too and the char was probably converted in file to cr.

I was rewrote the text file for button Labels on Mac (only with TexEdit.app) and now it is all OK. Thanks for help, the idea about size variables TXTDATA was for me incentive

Regards
Oldrich

Post Reply

Return to “Multimedia”