Java searching float number in String

前端 未结 7 2065
轻奢々
轻奢々 2020-12-02 02:35

let\'s say i have string like that:

eXamPLestring>1.67>>ReSTOfString

my task is to extract only 1.67 from string above.

7条回答
  •  情话喂你
    2020-12-02 03:08

    Here's how to do it in one line,

    String f = input.replaceAll(".*?([\\d.]+).*", "$1");
    

    If you actually want a float, here's how you do it in one line:

    float f = Float.parseFloat(input.replaceAll(".*?([\\d.]+).*", "$1")),
    

提交回复
热议问题