class Program { static void Main(string[] args) { string input = Console.ReadLine(); while (input.ToLower()!="exit") { string mess = ToDBC(input); Console.WriteLine(mess); input = Console.ReadLine(); } Console.ReadLine(); } /// <summary> /// 将字符串转为半角 /// </summary> /// <param name="input"></param> /// <returns></returns> public static string ToDBC(string input) { char[] c = input.ToCharArray(); for (int i = 0; i < c.Length; i++) { if (c[i] == 12288) { c[i] = (char)32; continue; } if (c[i] > 65280 && c[i] < 65375) c[i] = (char)(c[i] - 65248); } return new String(c); } }
效果图如下: