不同编码格式对同一字符串的表示为:
Console.Write("输入要编码的字符:"); string str = Console.ReadLine(); Console.Write("输入要编码的格式:"); string ss = Console.ReadLine(); Encoding en = Encoding.GetEncoding(ss); byte[] bytes = en.GetBytes(str); string str1 = BitConverter.ToString(bytes); Console.Write(ss + "格式编码后的结果为:"); Console.WriteLine(str1);
输出本机所有编码类型:
Console.WriteLine("输出本机所有编码类型信息:"); StringBuilder sb = new StringBuilder(); foreach (EncodingInfo ei in Encoding.GetEncodings()) { Encoding ed = ei.GetEncoding(); sb.AppendFormat("编码名称:{0},说明:{1}\n", ei.Name, ed.EncodingName); } Console.WriteLine(sb.ToString()); Console.ReadLine();