Extract numbers from an alpha numeric string using android

后端 未结 3 1962
粉色の甜心
粉色の甜心 2021-01-18 10:14

I have to extract only numeric values from String str=\"sdfvsdf68fsdfsf8999fsdf09\". How can I extract numbers from an alpha numeric string in android?

3条回答
  •  生来不讨喜
    2021-01-18 10:55

    String str="sdfvsdf68fsdfsf8999fsdf09";
    String numberOnly= str.replaceAll("[^0-9]", "");
    

    update:

    String str="fgdfg12°59'50\" Nfr | gdfg: 80°15'25\" Efgd";
    String[] spitStr= str.split("\\|");
    
    String numberOne= spitStr[0].replaceAll("[^0-9]", "");
    String numberSecond= spitStr[1].replaceAll("[^0-9]", "");
    

提交回复
热议问题