zoukankan      html  css  js  c++  java
  • 如何控制在DataGrid中不能输入全角数字,符号,字母?

    如何控制在DataGrid中不能输入全角数字,符号,字母? 
      ===============================================  
      1.屏蔽全角  
      2.把全角转为半角  
       
      private   string   ToDBS(string   str)//全角转半角  
      {  
        return   Regex.Replace(str,"[\\w]",new   MatchEvaluator(RegReplace));  
      }  
      private     string   RegReplace(Match   m)  
      {  
            if((int)m.Value[0]>=65281&(int)m.Value[0]<=65374)return   ((char)((int)m.Value[0]-65248)).ToString();  
            if((int)m.Value[0]==12288)return   ((char)32).ToString();;  
      return   m.Value;  
      }
    Top

      ///   半角转全角  
      ///   </summary>  
      ///   <param   name="BJstr"></param>  
      ///   <returns></returns>  
      static   public   string   GetQuanJiao(string   BJstr)  
      {  
      #region  
      char[]   c   =   BJstr.ToCharArray();  
      for   (int   i   =   0;   i   <   c.Length;   i++)  
      {  
      byte[]   b   =   System.Text.Encoding.Unicode.GetBytes(c,   i,   1);  
      if   (b.Length   ==   2)  
      {  
      if   (b[1]   ==   0)  
      {  
      b[0]   =   (byte)(b[0]   -   32);  
      b[1]   =   255;  
      c[i]   =   System.Text.Encoding.Unicode.GetChars(b)[0];  
      }  
      }  
      }  
       
      string   strNew   =   new   string(c);  
      return   strNew;  
       
      #endregion  
      }  
       
      ///   <summary>  
      ///   全角转半角  
      ///   </summary>  
      ///   <param   name="QJstr"></param>  
      ///   <returns></returns>  
      static   public   string   GetBanJiao(string   QJstr)  
      {  
      #region  
      char[]   c   =   QJstr.ToCharArray();  
      for   (int   i   =   0;   i   <   c.Length;   i++)  
      {  
      byte[]   b   =   System.Text.Encoding.Unicode.GetBytes(c,   i,   1);  
      if   (b.Length   ==   2)  
      {  
      if   (b[1]   ==   255)  
      {  
      b[0]   =   (byte)(b[0]   +   32);  
      b[1]   =   0;  
      c[i]   =   System.Text.Encoding.Unicode.GetChars(b)[0];  
      }  
      }  
      }  
      string   strNew   =   new   string(c);  
      return   strNew;  
      #endregion  
      }

    antony
    :antony1029@163.com
    :http://antony1029.cnblogs.com
  • 相关阅读:
    【C/C++】【类和对象】计算类所占的字节数
    【算法】【单调栈】单调栈
    【算法】【字符串】C语言常用库函数实现
    【算法】【字符串】Leetcode哈希表相关高频面试题
    ubuntu20.04安装测试uhttpd
    华为Mate14上安装Ubuntu20.04纪要
    shell判断参数值是否在数组内的方法
    降低PDF质量
    Ubuntu 16.04上安装Global阅读源代码工具
    Linux下好用的屏幕录像软件kazam及截图软件shutter
  • 原文地址:https://www.cnblogs.com/antony1029/p/989457.html
Copyright © 2011-2022 走看看