Skip to main content
FabianK007
Known Participant
March 30, 2017
Question

FrameMaker 2015 Script - Retrieved UTF-8 strings are stored as ANSI - Japanese Char

  • March 30, 2017
  • 0 replies
  • 288 views

Dear community,

I retrieve some strings from a *.txt file over a local network, and later store those into the variables of a *.fm file.

The *.txt file is UTF-8 encoded. However, the UTF-8 encoding changes to ANSI, the characters change e.g. from "面の定義" to "面の定義"

I don't understand why the encoding changed.

How can I encode the ANSI string back to UTF-8?

Thanks!

function GetProp(doc, information) {

    var conn = new Socket;

    if (conn.open ("localhost:8000", "UTF-8")) {

        var getRequest = "GET /workbench/" + doc + "/" + information + "/ HTTP/1.1\r\nHost: localhost\r\n\r\n";

        conn.encoding = "BINARY"; //this line does not seem to have impact

        conn.write(getRequest);

        var endlessLoopCounter = 0;

        var responseHeader = "";

       

        while(responseHeader.substring(responseHeader.length - 4, responseHeader.length) != "\r\n\r\n") {

            responseHeader += conn.read(1);

        }   

        var contentLength = 0;       

        var index1 = responseHeader.toLowerCase().indexOf("content-length:");

        var index2 = responseHeader.toLowerCase().indexOf("\r\n", index1);

        if(index2 < 0) responseHeader.toLowerCase().indexOf("\n", index1);

        if(index1 > -1) {

            contentLength = parseInt(responseHeader.substring(index1 + 15, index2));

        }

//here starts the reading

        var content = "";

        for(var i = 0; i < contentLength; i++) {

            content += conn.read(1);

        }     

        conn.close();

       return content;

  }

  return "error";

}

This topic has been closed for replies.