Created
January 30, 2012 06:55
-
-
Save haacked/1702966 to your computer and use it in GitHub Desktop.
Windows-1252 Encoding Round Trip Demo
This file contains hidden or 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; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var encoding = Encoding.GetEncoding(1252); | |
for (int b = Byte.MinValue; b <= Byte.MaxValue; b++) | |
{ | |
var data = new[] { (byte)b }; | |
string text = encoding.GetString(data); | |
var roundTripped = encoding.GetBytes(text); | |
if (!roundTripped.SequenceEqual(data)) | |
{ | |
Console.WriteLine("Rount Trip Failed At: " + b); | |
return; | |
} | |
} | |
Console.WriteLine("Round trip successful!"); | |
Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment