4
  1. I am gathering information from a HEBREW (WINDOWS-1255 / UTF-8 encoding) website using vbscript and WinHttp.WinHttpRequest.5.1 object.

For 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)
  1. When Viewing the file in notepad / notepad++, I see Hebrew as Gibrish / Gibberish. For example : äìëåú - äøá àáøäí éåñó - îåøùú

  2. I need a vbscript function to return Hebrew correctly, the function should be similar to the following http://www.pixiesoft.com/flip/ choosing the 2nd radio button and press convert button , you will see Hebrew correctly.

  • Is the text in UTF-8 or Windows-1255? They're not the same encoding. – Jon Skeet Jul 09 '12 at 06:07
  • @Jon Skeet: Apparently, it's Windows-1255, but this is just conjecture. The OP should probably identify the web page's URL and/or post a copy of the pertinent HTTP and/or HTML headers from the server. The actual hex bytes in the resulting file would also be more helpful than a copy/paste in an unidentified character set. – tripleee Jul 09 '12 at 07:59
  • Thanks for your quick feedback. So I am not sure, what should be the best course of action here ? – Etay Gudai 972-522-3322-47 Jul 09 '12 at 08:19
  • and regarding the encoding ...please refer to : Windows-1255. I also know that in the site I have mentioned above it is being executed on Server side....just looking for the function – Etay Gudai 972-522-3322-47 Jul 09 '12 at 08:40

2 Answers2

5

Your script is correctly fetching the byte stream and saving it as-is. No problems there.

Your problem is that the local text editor doesn't know that it's supposed to read the file as cp1255, so it tries the default on your machine of cp1252. You can't save the file locally as cp1252, so that Notepad will read it correctly, because cp1252 doesn't include any Hebrew characters.

What is ultimately going to be reading the file or byte stream, that will need to pick up the Hebrew correctly? If it does not support cp1255, you will need to find an encoding that is supported by that tool, and convert the cp1255 string to that encoding. Suggest you might try UTF-8 or UTF-16LE (the encoding Windows misleadingly calls 'Unicode'.)

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

Community
  • 1
  • 1
bobince
  • 528,062
  • 107
  • 651
  • 834
2

Thanks to Charming Bobince (that posted the answer), I am now able to see HEBREW correctly (saving a windows-1255 encoding to 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