This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Writing to file, UTF-8
#1
Hi

I have made this script that is testing my installation and writing the result to a file and then sends it to my email. The only problem I still have is that the messages written to the report contains some Nordic characters, and that returns some ugly results like "PÃ¥drag ble ikke endret under varmetest".

Is there any way to set the character set to the file when writing to it?

Creating the file itself:
Code:
errorFile = string.format('Feilmeldinger_%s.csv', os.date('%d-%m-%Y',log_start))


The code for adding a line to the table is:
Code:
table.insert(errorBuffer, addr.name .. '; Gikk ikke til 100% pådrag.')

Writing to file; 
Code:
result, err = io.writefile ('/home/ftp/' .. errorFile, table.concat(errorBuffer, '\r\n'))

Is there anywhere in those where I can add the character set?
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
#2
You can add UTF-8 byte order mark to your CSV like this:
Code:
bom = string.char(0xEF, 0xBB, 0xBF)
csv = bom .. table.concat(errorBuffer, '\r\n')
result, err = io.writefile ('/home/ftp/' .. errorFile, csv)
Reply
#3
(03.11.2020, 11:05)admin Wrote: You can add UTF-8 byte order mark to your CSV like this:
Code:
bom = string.char(0xEF, 0xBB, 0xBF)
csv = bom .. table.concat(errorBuffer, '\r\n')
result, err = io.writefile ('/home/ftp/' .. errorFile, csv)

As always, the help in here is fast and on the spot! Thx again!
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply


Forum Jump: