1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace Dtsc.WorkFlow 7 { 8 public class StringHelper 9 { 10 /**/ 11 /// <summary> 12 /// 转半角的函数(DBC case) 13 /// </summary> 14 /// <param name="input">任意字符串</param> 15 /// <returns>半角字符串</returns> 16 ///<remarks> 17 ///全角空格为12288,半角空格为32 18 ///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248 19 ///</remarks> 20 public static string ToDBC(string input) 21 { 22 char[] c = input.ToCharArray(); 23 for (int i = 0; i < c.Length; i++) 24 { 25 if (c[i] == 12288) 26 { 27 c[i] = (char)32; 28 continue; 29 } 30 if (c[i] > 65280 && c[i] < 65375) 31 c[i] = (char)(c[i] - 65248); 32 } 33 return new string(c); 34 } 35 } 36 }
转载于:https://www.cnblogs.com/caicheng/archive/2012/07/27/2611450.html