Skip to main content
brian_p_dts
Community Expert
Community Expert
May 11, 2020
Answered

Encoding issues writing to txt

  • May 11, 2020
  • 2 replies
  • 1372 views

Hi folks, having some issues with encoding some information I am getting from a scriptUI in Indesign into a dialog box. myDialogLine in the script below is taking several user inputs, including from a dropdown and some editboxes, and is trying to write the result to an existing text file. The new line is coming in in Chinese characters, even though the inputs are all English. The client's text file is slugged UTF 16. 

 

I will admit to not understanding a great deal about encoding. Anyone have some tips or pointers to troubleshoot this one? Thanks in advance. Here's the snippet where I'm writing to file. 

 

the_link.open('a');
the_link.encoding = "UTF-8";
the_link.writeln(myDialogLine);
the_link.close();

 

This topic has been closed for replies.
Correct answer Test Screen Name

I don't know the API you are using but I can tell you that UTF-16 and UTF-8 are utterly different and not interchangeable. Seeing "Chinese" is likely, but worse could happen. You either have to tell the API to use UTF-16, if it can (check the documentation), or convert the data.

2 replies

Test Screen NameCorrect answer
Legend
May 11, 2020

I don't know the API you are using but I can tell you that UTF-16 and UTF-8 are utterly different and not interchangeable. Seeing "Chinese" is likely, but worse could happen. You either have to tell the API to use UTF-16, if it can (check the documentation), or convert the data.

brian_p_dts
Community Expert
Community Expert
May 11, 2020

Thanks, and good point. I was trying to open the file as UTF-16, and had switched to UTF-8 to troubleshoot. This is using Extendscript, in which documenation is lacking. Any suggestions on converting a Javascript string to UTF16? 

 

Community Expert
May 11, 2020

Hi Brian,

 

Can you provide a sample data that you are not able to write into a text file. I can try and see if i can resolve it

 

-Manan

-Manan
brian_p_dts
Community Expert
Community Expert
May 11, 2020

Thanks, Manan, 

 

The data basically follows this: XXX XXXXXXXX XXX \t XXXX \r