How to convert Unicode Hebrew appears as Gibberish in VBScript?

  • I am collecting information from the HEBREW website (WINDOWS-1255 / UTF-8) using the vbscript object and WinHttp.WinHttpRequest.5.1.

Example:

Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1") ... 'writes the file as unicode (can't use Ascii) Set Fileout = FSO.CreateTextFile("c:\temp\myfile.xml", true, true) .... Fileout.WriteLine(objWinHttp.responsetext) 
  • When viewing a file in notepad / notepad ++, I see Hebrew as Gibrish / Gibberish. For example: ìmelå - øá àáøà áå - --îî - îåùùùù

  • I need a vbscript function to correctly return Hebrew, the function should be similar to the following http://www.pixiesoft.com/flip/ , select the second radio station and click the convert button, you will see Hebrew correctly.

+4
source share
2 answers

Your script correctly extracts the byte stream and saves it as it is. No problems.

Your problem is that the local text editor does not know that it should read the file as cp1255, so it is trying to install cp1252 by default on your computer. You cannot save the file locally as cp1252 so that Notepad reads it correctly because cp1252 does not contain Hebrew characters.

What ultimately will the file or stream of bytes read, which should correctly select Hebrew? If it does not support cp1255, you will need to find the encoding supported by this tool and convert the cp1255 string to this encoding. Suggest that you can try UTF-8 or UTF-16LE (Windows encoding is misleading "Unicode".)

Converting text between encodings in VBScript / JScript can be performed as a side effect of the ADODB stream. See an example in this answer .

+4
source

Thanks to Charming Bobince (who posted the answer), I can now correctly see HEBREW (saving windows-1255 encoding in a txt file (notpad)) by implementing the following:

 Function ConvertFromUTF8(sIn) Dim oIn: Set oIn = CreateObject("ADODB.Stream") oIn.Open oIn.CharSet = "X-ANSI" oIn.WriteText sIn oIn.Position = 0 oIn.CharSet = "WINDOWS-1255" ConvertFromUTF8 = oIn.ReadText oIn.Close End Function 
+1
source

All Articles