Highlighted

Encoding issues writing to txt

Adobe Community Professional ,
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();

 

Most Valuable Participant
Correct answer by Test Screen Name | Most Valuable Participant

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.

TOPICS
Scripting

Views

369

Likes

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

Encoding issues writing to txt

Adobe Community Professional ,
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();

 

Most Valuable Participant
Correct answer by Test Screen Name | Most Valuable Participant

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.

TOPICS
Scripting

Views

370

Likes

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
May 11, 2020 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
May 11, 2020 0
Adobe Community Professional ,
May 11, 2020

Copy link to clipboard

Copied

Thanks, Manan, 

 

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

Likes

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
Reply
Loading...
May 11, 2020 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
May 11, 2020 1
Adobe Community Professional ,
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? 

 

Likes

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
Reply
Loading...
May 11, 2020 0