using System;
using System.Text;
/// <summary>
/// 测试各种编码转换前后结果
/// </summary>
public class EncodingTest
{
[STAThread]
static void Main()
{
EncodingTest test;
test = new EncodingTest();
}
public byte[] m_bytes=new byte[256];
public StringBuilder sb = new StringBuilder(1024);
public EncodingTest()
{
for(int i=0;i<256;i++)
{
m_bytes[i]=(byte)i;
}
sb.Remove(0, sb.Length);
sb.Append(System.Text.Encoding.Unicode.GetString(m_bytes));
Console.WriteLine("Unicode" + sb.Length.ToString());
Console.WriteLine(BitConverter.ToString(System.Text.Encoding.Unicode.GetBytes(sb.ToString())));
sb.Remove(0, sb.Length);
sb.Append(System.Text.Encoding.ASCII.GetString(m_bytes));
Console.WriteLine("ASCII" + sb.Length.ToString());
Console.WriteLine(BitConverter.ToString(System.Text.Encoding.ASCII.GetBytes(sb.ToString())));
sb.Remove(0, sb.Length);
sb.Append(System.Text.Encoding.BigEndianUnicode.GetString(m_bytes));
Console.WriteLine("BigEndianUnicode" + sb.Length.ToString());
Console.WriteLine(BitConverter.ToString(System.Text.Encoding.BigEndianUnicode.GetBytes(sb.ToString())));
sb.Remove(0, sb.Length);
sb.Append(System.Text.Encoding.Default.GetString(m_bytes));
Console.WriteLine("Default" + sb.Length.ToString());
Console.WriteLine(BitConverter.ToString(System.Text.Encoding.Default.GetBytes(sb.ToString())));
sb.Remove(0, sb.Length);
sb.Append(System.Text.Encoding.GetEncoding("GB2312").GetString(m_bytes));
Console.WriteLine("GB2312" + sb.Length.ToString());
Console.WriteLine(BitConverter.ToString(System.Text.Encoding.GetEncoding("GB2312").GetBytes(sb.ToString())));
sb.Remove(0, sb.Length);
sb.Append(System.Text.Encoding.UTF32.GetString(m_bytes));
Console.WriteLine("UTF32" + sb.Length.ToString());
Console.WriteLine(BitConverter.ToString(System.Text.Encoding.UTF32.GetBytes(sb.ToString())));
sb.Remove(0, sb.Length);
sb.Append(System.Text.Encoding.UTF7.GetString(m_bytes));
Console.WriteLine("UTF7" + sb.Length.ToString());
Console.WriteLine(BitConverter.ToString(System.Text.Encoding.UTF7.GetBytes(sb.ToString())));
sb.Remove(0, sb.Length);
sb.Append(System.Text.Encoding.UTF8.GetString(m_bytes));
Console.WriteLine("UTF8" + sb.Length.ToString());
Console.WriteLine(BitConverter.ToString(System.Text.Encoding.UTF8.GetBytes(sb.ToString())));
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/abiho/archive/2006/03/01/612857.aspx
System.Text.Encoding 学习笔记
最新推荐文章于 2021-08-04 09:25:52 发布