| 内容 | C#全角半角转换,这里的对象是数字,因为全角数字和半角数字显示的样式是不一样的,而且在内存中所占字节也是不同的,为了更标准些,我们可以通过下面的函数转换用户输入中的全角数字,挺方便:
 view sourceprint?01///
 02/// 将全角数字转换为数字
 03///</summary>
 04///<param name="SBCCase"></param>
 05///<returns></returns>
 06public static string SBCCaseToNumberic(string SBCCase)
 07{
 08 char[] c = SBCCase.ToCharArray();
 09 for (int i = 0; i < c.Length; i++)
 10 {
 11 byte[] b = System.Text.Encoding.Unicode.GetBytes(c, i, 1);
 12 if (b.Length == 2)
 13 {
 14 if (b[1] == 255)
 15 {
 16 b[0] = (byte)(b[0] + 32);
 17 b[1] = 0;
 18 c[i] = System.Text.Encoding.Unicode.GetChars(b)[0];
 19 }
 20 }
 21 }
 22 return new string(c);
 23}
 |