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);
}
It means your Unicode text is getting converted to ANSI text somewhere. Since Unicode characters outside of Latin-1 can't be converted to ANSI, they are converted to question marks.
The QUESTION MARK is a request for clarity or confirmation. The QUESTION MARK emoji ( ) is often used in text messaging as a request for clarity or confirmation.
The question marks indicate font substitution occurred because your Mac does not have the same font that was used when the content was created. The substituted font does not have the glyphs (character shapes) that exist in the specified font that is not present.
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.
Web servers can return a response in whatever encoding they want, although they typically choose an encoding that matches the browser's preferred language.
The encoding used is returned as the charset
element of the Content-Type
header. In .NET you can retrieve the encoding used from the HttpWebResponse.CharacterSet property. You can use the returned charset to construct an Encoding object to use for reading the response:
var charset= response.CharacterSet;
var encoding = Encoding.GetEncoding(charset);
var sr= new StreamReader(response.GetResponseStream(),encoding);
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With