M.ArslanKhan
M.ArslanKhan

Reputation: 3898

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

Upvotes: 1

Views: 2212

Answers (4)

Umer Khalid
Umer Khalid

Reputation: 345

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

This will do the trick

Upvotes: 1

Gopal Gopi
Gopal Gopi

Reputation: 11131

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

Upvotes: 3

Rachit Mishra
Rachit Mishra

Reputation: 6112

Use replaceAll() method of String class.

string.replaceAll("\\d*$", "")

Upvotes: 1

Alessandro Roaro
Alessandro Roaro

Reputation: 4733

If the digits are only at the beginning of the String you could do it like this:

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

Upvotes: 3

Related Questions