Text Character Set Encoding in Scripting


I'm reading text files created by VSCode in a Mac computer using UTF8 encoding and settings the content into function comments in Toad Data Modeler. Characters seem corrupted. I guess it is related to file encoding. Maybe, it is a very basic task, but I couldn't figure it out.

Simplified example code:

// Read comments from file system. (Created by VSCode in MacOS in UTF8)
var fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.OpenTextFile(path, 1); // For reading
var content = (f.AtEndOfStream) ? "" : f.ReadAll();

// Get function object from Toad Data Modeler and set it's comments.
var func = Model.functions.getObjectByFullName("public.some_function");
func.comments = content;

Example of corrupted word:
"çok" becomes "çok".

Kind Regards,

I found a solution and want to share it here with others who may have the same question.

I use ADODB.Stream instead of Scripting.FileSystemObject which seems to support UTF-8.

var objStream = new ActiveXObject("ADODB.Stream");
objStream.Type = 2;
objStream.Charset = "UTF-8";
var txt = objStream.readText;
1 Like