#region 半角转换为全角 /// <summary> /// 半角转换为全角 ////转全角的函数(SBC case) ///任意字符串 ///全角空格为12288,半角空格为32 ///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248 /// </summary> /// <param name="input"></param> /// <returns></returns> public String ToSBC(String input) { // 半角转全角: char[] c = input.ToCharArray(); for (int i = 0; i < c.Length; i++) { if (!IsWhole(input)) { if (c[i] == 32)//转换空格 { c[i] = (char)12288; continue; } if (c[i] < 127) c[i] = (char)(c[i] + 65248); } } return new String(c); } /// <summary> /// 判断是否为全角 /// </summary> /// <param name="checkString"></param> /// <returns></returns> public bool IsWhole(string checkString) { string containNUmWordS = @"^[a-z|A-Z|0-9|\u4e00-\u9fa5\‘ ‘()]*$";//有数字字母汉字空格 return Regex.IsMatch(checkString, containNUmWordS); } #endregion
时间: 2024-10-09 19:57:51