标签:str 字符 public har summary for sum 表示 return
public class ConvertDBCAndSBC { /// <summary>半角转成全角 /// 半角空格32,全角空格12288 /// 其他字符半角33~126,其他字符全角65281~65374,相差65248 /// </summary> /// <param name="input"></param> /// <returns></returns> public static string DBCToSBC(string input) { char[] cc = input.ToCharArray(); for (int i = 0; i < cc.Length; i++) { if (cc[i] == 32) { // 表示空格 cc[i] = (char)12288; continue; } if (cc[i] < 127 && cc[i] > 32) { cc[i] = (char)(cc[i] + 65248); } } return new string(cc); } /// <summary>全角转半角 /// 半角空格32,全角空格12288 /// 其他字符半角33~126,其他字符全角65281~65374,相差65248 /// </summary> /// <param name="input"></param> /// <returns></returns> public static string SBCToDBC(string input) { char[] cc = input.ToCharArray(); for (int i = 0; i < cc.Length; i++) { if (cc[i] == 12288) { // 表示空格 cc[i] = (char)32; continue; } if (cc[i] > 65280 && cc[i] < 65375) { cc[i] = (char)(cc[i] - 65248); } } return new string(cc); } }
from:https://www.cnblogs.com/zjbky/p/7477737.html
标签:str 字符 public har summary for sum 表示 return
原文地址:https://www.cnblogs.com/liuqiyun/p/12928331.html