Skip to content

Instantly share code, notes, and snippets.

@lodejard
Created December 27, 2014 03:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lodejard/4f1273b709244273e520 to your computer and use it in GitHub Desktop.
Save lodejard/4f1273b709244273e520 to your computer and use it in GitHub Desktop.
RemoveBOM xunit function
[Fact]
public void RemoveBom()
{
foreach (var file in new DirectoryInfo("..\\..").EnumerateFiles("*", SearchOption.AllDirectories))
{
try
{
var allBytes = File.ReadAllBytes(file.FullName);
var allText = File.ReadAllText(file.FullName);
if (allBytes.Length - allText.Length == 3 &&
allBytes[0] == 0xef &&
allBytes[1] == 0xbb &&
allBytes[2] == 0xbf)
{
Console.WriteLine("{0} {1}", file.FullName, file.Length);
File.WriteAllText(file.FullName, allText, Encoding.Default);
}
}
catch
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment