Created
April 7, 2016 14:58
-
-
Save nex3z/fa5f6dad83fa9e5bcd16271829a71079 to your computer and use it in GitHub Desktop.
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
// 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