NumberFormatException when parsing Hindi numbers

后端 未结 5 1904
走了就别回头了
走了就别回头了 2021-01-25 05:33

I have an android application and today I have got a crash report which contains this: \"NumberFormatException\"

Th

5条回答
  •  渐次进展
    2021-01-25 05:56

    Try this. This will remove non numeric characters.

      Pattern p = Pattern.compile("(\\d+)"); 
      Matcher m = p.matcher(str); // str is input String
      while(m.find()) {
        System.out.println(m.group(1));
      }
    

    If you are dealing with double(with decimal places). you can try this

        String text = "123.0114cc";
        String numOnly = text.replaceAll("\\p{Alpha}","");
        double numVal = Double.valueOf(numOnly);
        System.out.println(numVal);
    

提交回复
热议问题