在字符串中寻找数字的方法 JAVA版

 
 
//在字符串中寻找数字的函数
 private  double check(String x){
      char text[]=x.toCharArray();
     x.trim();
      String number="";
      for(int i=0;i<x.length();i++){
     try{
         
          number+=Integer.parseInt(""+text[i]);

      }catch (NumberFormatException e){
         if(text[i]=='-'||text[i]=='.')
             number+=text[i];
          continue;
      }
      
      }

     double result=0;
     try{

result=Double.parseDouble(""+number);}
     catch (Exception e){
      result=0;
     }
  
     return  result;
  }


猜你喜欢

转载自blog.csdn.net/qq_41105058/article/details/80037988
今日推荐