半角与全角的相互转换
1 /// <summary> 2 /// 转全角的函数(SBC case) 3 /// </summary> 4 /// <param name="input">任意字符串</param> 5 /// <returns>全角字符串</returns> 6 ///<remarks> 7 ///全角空格为12288,半角空格为32 8 ///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248 9 ///</remarks> 10 public static string ToSBC(string input) 11 { 12 //半角转全角: 13 char[] c=input.ToCharArray(); 14 for (int i = 0; i < c.Length; i++) 15 { 16 if (c[i]==32) 17 { 18 c[i]=(char)12288; 19 continue; 20 } 21 if (c[i]<127) 22 c[i]=(char)(c[i]+65248); 23 } 24 return new string(c); 25 } 26 27 28 /// <summary> 转半角的函数(DBC case) </summary> 29 /// <param name="input">任意字符串</param> 30 /// <returns>半角字符串</returns> 31 ///<remarks> 32 ///全角空格为12288,半角空格为32 33 ///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248 34 ///</remarks> 35 public static string ToDBC(string input) 36 { 37 char[] c=input.ToCharArray(); 38 for (int i = 0; i < c.Length; i++) 39 { 40 if (c[i]==12288) 41 { 42 c[i]= (char)32; 43 continue; 44 } 45 if (c[i]>65280 && c[i]<65375) 46 c[i]=(char)(c[i]-65248); 47 } 48 return new string(c); 49 }