62,074
社区成员
发帖
与我相关
我的任务
分享
static void Main(string[] args)
{
String str = "测试数据";
Encoding gb2312 = Encoding.GetEncoding("GB2312");
Byte[] gb2312Bytes = gb2312.GetBytes(str);
// Test starts: GB2312 bytes are what you have now
Console.WriteLine("============= GB2312 bytes ================");
foreach (Byte b in gb2312Bytes)
{
Console.Write("{0:x} ", b);
}
Console.WriteLine();
Console.WriteLine("===========================================");
String str1 = gb2312.GetString(gb2312Bytes);
//Console.WriteLine(str1);
Byte[] utf8Bytes = Encoding.UTF8.GetBytes(str1);
// Test result: UTF-8 bytes are what you want
Console.WriteLine("============= UTF-8 bytes =================");
foreach (Byte b in utf8Bytes)
{
Console.Write("{0:x} ", b);
}
Console.WriteLine();
Console.WriteLine("===========================================");
Console.ReadLine();
}
============= GB2312 bytes ================
b2 e2 ca d4 ca fd be dd
===========================================
============= UTF-8 bytes =================
e6 b5 8b e8 af 95 e6 95 b0 e6 8d ae
===========================================