Page 1 of 1

save text into UTF8 file

Posted: Thu Jan 25, 2018 10:24 pm
by operoutka
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

Re: save text into UTF8 file

Posted: Thu Jan 25, 2018 10:27 pm
by matthiasr
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

Re: save text into UTF8 file

Posted: Thu Jan 25, 2018 10:46 pm
by Klaus
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

Re: save text into UTF8 file

Posted: Fri Jan 26, 2018 7:24 am
by operoutka
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

Re: save text into UTF8 file

Posted: Fri Jan 26, 2018 8:21 am
by SparkOut
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.

Re: save text into UTF8 file

Posted: Fri Jan 26, 2018 11:19 am
by Klaus
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?

Re: save text into UTF8 file

Posted: Fri Jan 26, 2018 1:49 pm
by operoutka
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

Re: save text into UTF8 file

Posted: Fri Jan 26, 2018 1:51 pm
by operoutka
Hi,

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

Regards,

Oldrich

Re: save text into UTF8 file

Posted: Fri Jan 26, 2018 1:58 pm
by Klaus
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)
...

Re: save text into UTF8 file

Posted: Fri Jan 26, 2018 7:12 pm
by operoutka
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

Re: save text into UTF8 file

Posted: Fri Jan 26, 2018 10:44 pm
by operoutka
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