Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're going to potentially run into a problem with your implementation because of the <code>StringReader()</code>. Somewhere along the line someone needs to turn raw bytes into a string. Unless you're doing something special before this then .Net will do this for you and will usually use the computer defaults.</p> <p>The problem with the 8-bit era was that the 8th bit had dozens of implementations (if not more) and there's no real way to tell from the bytes which implementation to use. If you're using the ASCII, anything with the 8th bit set will get converted to ASCII 63 - <code>?</code>. If you're using UTF-8, anything with the 8th bit set will try to read the next one to five characters (<a href="http://en.wikipedia.org/wiki/UTF-8" rel="nofollow noreferrer">see Wikipedia for more info</a>) and if that doesn't work it will get converted to UTF-8 65533 <code>�</code> which is what you're seeing. If you manually specify the encoding such as the one you're being given <code>koi8-r</code> then that 8th bit will be parsed properly. Below is sample code that shows this off. Instead of dumping to the <code>Console</code> I'm messaging boxing but you can switch that as long as you remember to <a href="https://stackoverflow.com/a/5750227/231316">change your console's encoding</a>.</p> <pre><code>var bytes = new byte[] { 226 }; var s1 = System.Text.Encoding.ASCII.GetString(bytes);//Invalid var s2 = System.Text.Encoding.UTF8.GetString(bytes);//Invalid var s3 = System.Text.Encoding.GetEncoding("koi8-r").GetString(bytes); //Б MessageBox.Show(String.Format("{0} {1} {2}", s1, s2, s3)); </code></pre> <p>To summarize, if you're getting the UTF-8 replacement character (which you are) that means that you've lost the original value of those bytes and you need to fix it earlier. Whatever is converting the bytes to string needs to take <code>Content-Type: text/plain; charset="koi8-r";</code> into account, you can't do it after the fact.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload