简体   繁体   中英

how to remove digits or numeric characters from the string

I have A small string which include digit for example

 "1 Al-Fâtihah"
,"2 Al-Baqarah"
,"3 Âl-'Imrân"
,"4 An-Nisâ'"
,"5 Al-Mâ'idah"
,"6 Al-An'âm"
,"7 Al-A'râf"
,"8 Al-Anfâl"

I want to remove digits from the string.working on android java

use String.replaceAll(String,String) method...

ex:

    String s = "awhefqo1234akwfn";
    String string = s.replaceAll("[0-9]", "");// prints awhefqoakwfn

here [0-9] indicates a regular expression which replaces all digits with a empty String

如果数字仅在String的开头,您可以这样做:

String res = string.substring(2, string.length);

使用String类的replaceAll()方法。

string.replaceAll("\\d*$", "")
String s = "abcd123bcd";
s = s.replaceAll("\\d", "");

This will do the trick

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM