how to extract numeric values from input string in java

后端 未结 15 1974
说谎
说谎 2020-12-13 16:25

How can I extract only the numeric values from the input string?

For example, the input string may be like this:

String str=\"abc d 1234567890pqr 548         


        
15条回答
  •  一生所求
    2020-12-13 16:54

    You can use str = str.replaceAll("replaced_string","replacing_string");

    String str=" abc d 1234567890pqr 54897";
    String str_rep1=" abc d ";
    String str_rep2="pqr ";
    String result1=str.replaceAll("", str_rep1);
    String result2=str.replaceAll(",",str_rep2);
    

    also what npinti suggests is fine to work with.

提交回复
热议问题