Created
November 19, 2010 19:35
-
-
Save jstclair/707017 to your computer and use it in GitHub Desktop.
How to get a UTF8Encoder with a BOM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Text; | |
namespace BomEncoding | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("with BOM:"); | |
WriteUtf(new UTF8Encoding(true)); | |
Console.WriteLine("without BOM:"); | |
WriteUtf(new UTF8Encoding(false)); | |
Console.ReadLine(); | |
} | |
private static void WriteUtf(UTF8Encoding encoder) | |
{ | |
var preamble = encoder.GetPreamble(); | |
preamble.ToList().ForEach(x => Console.Write("[{0}] ", x)); | |
Console.WriteLine(); | |
var text = encoder.GetBytes("Some Text"); | |
text.ToList().ForEach(x => Console.Write("[{0}] ", x)); | |
Console.WriteLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment