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+$");     
            }     

  • 相关阅读:
    【Linux】freetds安装配置连接MSSQL
    【MySQL】Sysbench性能测试
    【MySQL】mysql buffer pool结构分析
    【MySQL】MySQL锁和隔离级别浅析一
    Spring Boot 1.4测试的改进
    Spring Boot 定时任务的使用
    linux:nohup 不生成 nohup.out的方法
    Spring Boot应用的后台运行配置
    深入理解Session与Cookie(一)
    学习Maven之Cobertura Maven Plugin
  • 原文地址:https://www.cnblogs.com/meiCode/p/3382498.html
Copyright © 2011-2022 走看看