zoukankan      html  css  js  c++  java
  • 如何判断字符串是否存在数字

             //isDigit  
                    public static bool isNumberic1(this string _string) 
                    {
                        if (string.IsNullOrEmpty(_string))  
                            return false;        
                        foreach (char c in _string) 
                        {                 
                            if (!char.IsDigit(c))//if(c<'0' || c>'9')//最好的方法,在下面测试数据中再加一个0,然后这种方法效率会搞10毫秒左右   
                                return false;            
                        }           
                        return true;       
                    }         
            //vb isnumberic     
            public static bool isNumberic2(this string _string)  
            {             
                return !string.IsNullOrEmpty(_string) && Microsoft.VisualBasic.Information.IsNumeric(_string);
            }         
            //try parese  
            public static bool isNumberic3(this string _string)  
            {             
                if (string.IsNullOrEmpty(_string)) 
                    return false;    
                int i = 0;           
                return int.TryParse(_string, out i);   
            }       
            //try catch      
            public static bool isNumberic4(this string _string)   
            {            
                if (string.IsNullOrEmpty(_string))  
                    return false;           
                try { int.Parse(_string); }    
                catch { return false; }    
                return true;         }     
            //regex        
            public static bool isNumberic5(this string _string)  
            {            
                return !string.IsNullOrEmpty(_string) && Regex.IsMatch(_string, "^d+$");     
            }     

  • 相关阅读:
    sql:drop、delete、truncate的区别
    pgsql:插入数据,存在就更新,不存在就插入
    sql:多表连接查询
    克隆模式
    canvas 实现星空闪烁的效果,鼠标滑动,连接周围的点
    JS微信网页图片预览可放大缩小
    muduo_base 02 (Atomic)
    muduo_base 01 (Timestamp)
    select/poll/epoll
    socket编程(二)
  • 原文地址:https://www.cnblogs.com/meiCode/p/3382498.html
Copyright © 2011-2022 走看看