Java searching float number in String

前端 未结 7 2070
轻奢々
轻奢々 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:14

    You could try matching the digits using a regular expression

    \\d+\\.\\d+
    

    This could look something like

    Pattern p = Pattern.compile("\\d+\\.\\d+");
    Matcher m = p.matcher("eXamPLestring>1.67>>ReSTOfString");
    while (m.find()) {
        Float.parseFloat(m.group());
    }
    

提交回复
热议问题