Java: removing numeric values from string

前端 未结 7 1905
心在旅途
心在旅途 2020-12-01 18:03

I have suceeded with the help of this community in removing numeric values from user input, however, my code below will only retrieve the alpha characters before the numeric

7条回答
  •  醉酒成梦
    2020-12-01 18:29

    You can use:

    firstname1 = firstname1.replaceAll("[0-9]","");
    

    This will remove all numeric values from String firstName1.

        String firstname1 = "S1234am";
        firstname1 = firstname1.replaceAll("[0-9]","");
        System.out.println(firstname1);//Prints Sam
    

提交回复
热议问题