Skip to content

Instantly share code, notes, and snippets.

@blairconrad
Created January 17, 2014 14:47
Show Gist options
  • Save blairconrad/8474567 to your computer and use it in GitHub Desktop.
Save blairconrad/8474567 to your computer and use it in GitHub Desktop.
Fun with encodings!
> var defaultEncoding = Encoding.Default;
> var myEncoding = Encoding.GetEncoding(defaultEncoding.CodePage, new EncoderReplacementFallback("?"), new DecoderReplacementFallback("?"));
> (int)(defaultEncoding.GetBytes("\u042E")[0]) // \u042E is "Ю" - Yu (Cyrillic)
63 // "?"
> (int)(myEncoding.GetBytes("\u042E")[0])
63
> (int)(defaultEncoding.GetBytes("\u99AC")[0]) // \u99AC is "馬" - Horse
63
> (int)(myEncoding.GetBytes("\u99AC")[0])
63
> (int)(defaultEncoding.GetBytes("\u03C0")[0]) // \u03C0 is "π" - pi (Greek)
112 // "p" - this is what we want to avoid, I think.
> (int)(myEncoding.GetBytes("\u03C0")[0])
63 // "?" - this is better
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment