using System;namespace Example
{
public class Program
{
public static void Main()
{
string s = "H你";
Console.WriteLine("----------Default-----------"); for(int i = 0 ; i < s.Length; i++)
{
string str = s.Substring(i,1);
byte[] bytes = System.Text.Encoding.Default.GetBytes(str);
foreach(byte b in bytes)
{
Console.WriteLine("{0:d},{1:X}",b,b);
}
} Console.WriteLine("----------ASCII-----------"); for(int i = 0 ; i < s.Length; i++)
{
string str = s.Substring(i,1);
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(str);
foreach(byte b in bytes)
{
Console.WriteLine("{0:d},{1:X}",b,b);
}
} Console.WriteLine("----------Unicode-----------"); for(int i = 0 ; i < s.Length; i++)
{
string str = s.Substring(i,1);
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(str);
foreach(byte b in bytes)
{
Console.WriteLine("{0:d},{1:X}",b,b);
}
} Console.WriteLine("----------UTF7-----------"); for(int i = 0 ; i < s.Length; i++)
{
string str = s.Substring(i,1);
byte[] bytes = System.Text.Encoding.UTF7.GetBytes(str);
foreach(byte b in bytes)
{
Console.WriteLine("{0:d},{1:X}",b,b);
}
} Console.WriteLine("----------UTF8-----------"); for(int i = 0 ; i < s.Length; i++)
{
string str = s.Substring(i,1);
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
foreach(byte b in bytes)
{
Console.WriteLine("{0:d},{1:X}",b,b);
}
}
Console.Read();
}
}
}
{
public class Program
{
public static void Main()
{
string s = "H你";
Console.WriteLine("----------Default-----------"); for(int i = 0 ; i < s.Length; i++)
{
string str = s.Substring(i,1);
byte[] bytes = System.Text.Encoding.Default.GetBytes(str);
foreach(byte b in bytes)
{
Console.WriteLine("{0:d},{1:X}",b,b);
}
} Console.WriteLine("----------ASCII-----------"); for(int i = 0 ; i < s.Length; i++)
{
string str = s.Substring(i,1);
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(str);
foreach(byte b in bytes)
{
Console.WriteLine("{0:d},{1:X}",b,b);
}
} Console.WriteLine("----------Unicode-----------"); for(int i = 0 ; i < s.Length; i++)
{
string str = s.Substring(i,1);
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(str);
foreach(byte b in bytes)
{
Console.WriteLine("{0:d},{1:X}",b,b);
}
} Console.WriteLine("----------UTF7-----------"); for(int i = 0 ; i < s.Length; i++)
{
string str = s.Substring(i,1);
byte[] bytes = System.Text.Encoding.UTF7.GetBytes(str);
foreach(byte b in bytes)
{
Console.WriteLine("{0:d},{1:X}",b,b);
}
} Console.WriteLine("----------UTF8-----------"); for(int i = 0 ; i < s.Length; i++)
{
string str = s.Substring(i,1);
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
foreach(byte b in bytes)
{
Console.WriteLine("{0:d},{1:X}",b,b);
}
}
Console.Read();
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货