xiexiaoxia
String regEx="[^0-9]";//正则表达式
        String str="sd34fgsfgh6756gff1223bvhgh";//待处理的字符串
        Pattern pattern = Pattern.compile(regEx);
        Matcher matcher = pattern.matcher(str);//匹配除数字以外的字符
        String num=matcher.replaceAll("").trim();//使用空字符替换匹配到的字符,最后只留下数字
        System.out.println(Integer.valueOf(num));//将字符串转换成数值输出

输出:

 

String a="34.98";
System.out.println(a.replaceAll("[.]",""));//去掉数字中的小数点

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-01
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-22
  • 2022-12-23
相关资源
相似解决方案