code_junkie

Why isn't the Byte Order Mark emitted from UTF8Encoding.GetBytes?

Nov 13th, 2011
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. UTF8Encoding enc = new UTF8Encoding(true/*include Byte Order Mark*/);
  2. byte[] data = enc.GetBytes("a");
  3. // data has length 1.
  4. // I expected the BOM to be included. What's up?
  5.  
  6. UTF8Encoding enc = new UTF8Encoding(true);
  7. byte[] data = enc.GetBytes("a");
  8. byte[] combo = enc.GetPreamble().Concat(data).ToArray();
  9.  
  10. byte[] preamble = enc.GetPreamble();
Add Comment
Please, Sign In to add comment