• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Encoding issues writing to txt

Community Expert ,
May 11, 2020 May 11, 2020

Copy link to clipboard

Copied

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();

 

TOPICS
Scripting

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 11, 2020 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.

Votes

Translate

Translate
Community Expert ,
May 11, 2020 May 11, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2020 May 11, 2020

Copy link to clipboard

Copied

LATEST

Thanks, Manan, 

 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 11, 2020 May 11, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2020 May 11, 2020

Copy link to clipboard

Copied

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? 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines