public
Created

Windows-1252 Encoding Round Trip Demo

  • Download Gist
windows-1252-roundtrip.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
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();
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.