0

我正在尝试在网站中查找希伯来语字符串。附上阅读代码。

之后我尝试使用 streamReader 读取文件,但我无法匹配其他语言的字符串。我该怎么办?

   // used on each read operation
    byte[] buf = new byte[8192];

    // prepare the web page we will be asking for
    HttpWebRequest request = (HttpWebRequest)
        WebRequest.Create("http://www.webPage.co.il");

    // execute the request
    HttpWebResponse response = (HttpWebResponse)
        request.GetResponse();

    // we will read data via the response stream
    Stream resStream = response.GetResponseStream();

    string tempString = null;
    int count = 0;
    FileStream fileDump = new FileStream(@"c:\dump.txt", FileMode.Create);
    do
    {
        count = resStream.Read(buf, 0, buf.Length);
        fileDump.Write(buf, 0, buf.Length);

    }
    while (count > 0); // any more data to read?

    fileDump.Close();
4

2 回答 2

0

您缺少适当的编码器,请查看WebResponse.GetResponseStream 方法了解详细信息

更新:使用希伯来语 (Windows) 编码为 1255

Encoding encode = System.Text.Encoding.GetEncoding(1255); // Hebrew (Windows) 

// Pipe the stream to a higher level stream reader with the required encoding format. 
 StreamReader readStream = new StreamReader( resStream , encode );
于 2010-06-09T18:04:29.577 回答
0

解决了。

问题是选择了错误的编码,我选择了 utf-8 这并不总是正确的答案:)

关键线:

Encoding encode = System.Text.Encoding.GetEncoding("windows-1255");
StreamReader readStream = new StreamReader(ReceiveStream, encode);
于 2010-06-09T19:28:03.900 回答