using System; class DistrictCode { public static void Main(string[] args) { while(true) { Console.Write("请输入(输入“E”退出):"); string inputString =Console.ReadLine(); if(iSnputString=="e"||inputString=="E") { break; } else { Console.WriteLine(TextTOQwm(inputString)); } } } public static string TextTOQwm(string character) { string coding=""; int i1=0; int i2=0; int i3=0; for(int i=0;i<character.Length;i++) { byte [] bytes=System.Text.Encoding.Default.GetBytes(character.Substring(i,1)); i1=(short)(bytes[0]); if(bytes.Length!=1) { i2=(short)(bytes[1]); i3=1; } else { i2=65536; i3=-1; } int chrasc=i1*256+i2-65536; if(chrasc>0 && chrasc<160) { Console.WriteLine("只能输入汉字"); } else { if(i3==-1) { Console.WriteLine("只能输入汉字"); } else { string lowCode=System.Convert.ToString(Math.Abs (Convert.ToInt32(System.Convert.ToString(bytes[0]))-160)); if(lowCode.Length==1) { lowCode="0"+lowCode; } string hightCode=System.Convert.ToString(Math.Abs (Convert.ToInt32(System.Convert.ToString(bytes[1]))-160)); if(hightCode.Length==1) { hightCode="0"+hightCode; } coding+=character.Substring(i,1)+(lowCode+hightCode); } } } return coding; } }