zoukankan      html  css  js  c++  java
  • 全角转半角

    //全角字符从的unicode编码从65281~65374  

      //   半角字符从的unicode编码从  33~126   

     //    * 差值65248 

     //   空格比较特殊,全角为       12288,半角为       32     

       public char FullCode2HalfCode(char c)    {      

      //得到c的编码    

        byte[] bytes = System.Text.Encoding.Unicode.GetBytes(c.ToString());

            int H = Convert.ToInt32(bytes[1]);        int L = Convert.ToInt32(bytes[0]);
            //得到unicode编码  

          int value = H * 256 + L;
            //是全角      

      if (value >= 65281 && value <= 65374)        {            int halfvalue = value - 65248;

    //65248是全半角间的差值。  

              byte halfL = Convert.ToByte(halfvalue);
                bytes[0] = halfL;            bytes[1] = 0;        }   

         else if (value == 12288)        {    

            int halfvalue = 32;         

       byte halfL = Convert.ToByte(halfvalue);
                bytes[0] = halfL;            bytes[1] = 0;    

        }        else        {          

      return c;        }
            //将bytes转换成字符     

       string ret = System.Text.Encoding.Unicode.GetString(bytes);
            return Convert.ToChar(ret);  

      }

  • 相关阅读:
    luogu P3239 [HNOI2015]亚瑟王
    android之软件键盘
    Eclipse输入智能提示设置
    防止反编译
    二进制数据读写
    数据类型转换
    类对象的读写文件
    Eclipse 快捷键
    修改IP
    Android eclipse 运行项目设置程序默认安装到SD卡
  • 原文地址:https://www.cnblogs.com/leibg/p/1867045.html
Copyright © 2011-2022 走看看