Hi all! I have a question related to garbled chara...
# suitescript
m
Hi all! I have a question related to garbled characters. I have issue with special characters and file encodings. There is strings where is special characters like
ö
or
ä
. And NetSuite shows those now wrong. My file says in Notepad++ that it is ANSI / CR LF encoded, but when in script I check
fileObj.encoding
it says that file is UTF-8. Here is test example with string:
Test Characteröä
How could I solve this issue? The file comes automatically to my script from server, so I can't manually change the encoding...
w
It you can't specify the encoding while uploading the file, you might need to read the contents and then convert it. I think I've used N/encode-module in the past to convert it to the correct format.
b
honestly depends on how you are getting the file in script
a lot of the time suitescript assumes utf-8, and its a painful working outside of it
when you do have a choice, the list of supported encoding are small
m
I couldn't make it work the way @Watz suggested. @battk I have the file in File cabinet and I just use
file.load
. Then I use the
fileObj.lines.iterator()
to go trough the lines. I tried to look at the supported encodings. But is any of those even close to the ANSI / CR LF coding my file seems to be?
b
ANSI / CR LF is not really the name of an encoding
ansi is a name of an informal grouping of encoding
hopefully yours is
WINDOWS_1252
cr lf isnt encoding related at all, its just what your software is using to show a new nline
your best best choice is making whatever saved the file into the file cabinet set the correct encoding
💯 1
w
hmm, I think my example was from when we received a UTF-8 file without file-extension that got interpreted as "OTHERBINARY". Unfortunately it didn't apply to this case.
m
@battk so how should I change the encoding? What kind of operations I need to do in script? If we asume that I have file in filecabinet that is WINDOWS_1252 and I want to change that to UTF-8?
b
whatever is uploading the file into the file cabinet needs to set the correct encoding
all files are represented as bytes
and encoding are how the bytes are converted into text
when suitescript is loading the file, it converts into the text according to the encoding set on the file
if the encoding is wrong, the text is going to be wrong
the only things that tend to survive are string that can be represented with ascii encoding, which most encoding build off of
m
So there is no way to change coding of the file with suitescript?
b
you can change it, but the contents have already been destroyed by the time you can
m
Ok, thanks!