Why does he display question marks in the message box instead of the text?

advertisements

Why does it shows question marks on the message box instead of text

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://teamxor.net/vb/tx48/"+ page);

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

StreamReader sr = new StreamReader(response.GetResponseStream());

string result = sr.ReadToEnd();

Regex r = new Regex("<div>.*?</div>");
MatchCollection mr = r.Matches(result);

foreach (Match m in mr)
{
    MessageBox.Show(m.Value, "Test", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
}


The problem lies in the use of a non-default code page. Your HTML shows you are using code page 1256. You have to tell .NET that, else it thinks it is UTF-8:

StreamReader sr = new StreamReader( response.GetResponseStream()
                                  , Encoding.GetEncoding(1256) // <-- this one
                                  );

Use Encoding.GetEncoding to get the right code page. I suggest to use UTF8 instead, since that is easily recognized by .NET.