There are several cases where we find alphanumeric characters like Vehicle Name plates (e.g. UP 16 BL 4405), Address Number plates (e.g. Aditya Agnihotri, Flat no, G- 102, Noida) and so on.
Sometimes we only need the digits from such alphanumeric strings. Now if we see the Address which is – “Aditya Agnihotri, Flat no, G- 102, Noida”, it contains alphabets, comma, hyphen and so on. But form this Address we only need to extract digits which i.e. 102. Now to have such logic we need to write few lines of code in every language.
But here i am providing you single line solution in JAVA.
String Address = "Aditya Agnihotri, Flat no, G- 102, Noida" String Address_Digits = Address.replaceAll("[-+.^:,]",""); System.out.println("Flat number is - "+Address_Digits);
O/P of above program – 102
Happy Coding 🙂
4 thoughts on “Java Code to Remove Special Characters from a String.”
Thanks for your personal marvelous posting! I seriously enjoyed reading
it, you will be a great author. I will make sure to bookmark your blog
and may come back very soon. I want to encourage you to continue
your great job, have a nice weekend!
My partner and I stumbled over here different web page and thought I may as well check
things out. I like what I see so now i am following you.
Look forward to checking out your web page again.
Good answers in return of this question with solid arguments and describing all
Wonderful goods from you, man. I have understand your
stuff previous to and you are just too wonderful.
I really like what you’ve acquired here, really like what you’re saying and the way
in which you say it. You make it enjoyable and
you still take care of to keep it smart. I can’t wait to read
far more from you. This is actually a great site.