Skip to content

Instantly share code, notes, and snippets.

@nex3z nex3z/codec.cs
Created Apr 7, 2016

Embed
What would you like to do?
// hello 你好
// hello 浣犲ソ
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EncodingTest
{
class Program
{
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder();
string source = "hello 浣犲ソ";
sb.AppendLine("Encoding.Default.CodePage = " + Encoding.Default.CodePage);
sb.AppendLine("Encoding.Default.WindowsCodePage = " + Encoding.Default.WindowsCodePage);
sb.AppendLine("Encoding.UTF8.CodePage = " + Encoding.UTF8.CodePage);
foreach (var e1 in Encoding.GetEncodings())
{
foreach (var e2 in Encoding.GetEncodings())
{
byte[] unknow = Encoding.GetEncoding(e1.CodePage).GetBytes(source);
string result = Encoding.GetEncoding(e2.CodePage).GetString(unknow);
sb.AppendLine(string.Format("{0} => {1} : {2}", e1.CodePage, e2.CodePage, result));
}
}
File.WriteAllText("test.txt", sb.ToString());
}
}
}
// Encoding.Default.CodePage = 936
// Encoding.Default.WindowsCodePage = 936
// Encoding.UTF8.CodePage = 65001
// Line 3503: 936 => 65001 : hello 你好
// Line 17319: 50227 => 65001 : hello 你好
// Line 17599: 51936 => 65001 : hello 你好
// Line 18051: 54936 => 65001 : hello 你好
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.