Code to remove Junk or Strange symbols(Garbage symbols) from String in Android.

String testStr="hii!@#$%^&*()_+=~`?|{}[]...,<>:;äöüÄÖÜßéèáàúùóòêìó213";
testStr=testStr. replaceAll("[^a-zA-Z0-9!@#$%^&*()-_=:.;{[}]|'?/<,>/\"\\+]", "");


Use [^\p{L}\p{Nd}] - this matches all (Unicode) characters that are neither letters nor (decimal) digits.
In Java:
String resultString = subjectString.replaceAll("[^\\p{L}\\p{Nd}]", "");

I changed \p{N} to \p{Nd} because the former also matches some number symbols like ¼; the latter doesn't. See it on


Popular posts from this blog

Custom Dialog with no title and full screen in Android

code to display .pdf,.text,.DOC,.DOCX,.doc extension files exists in SDCard

Best working code to set Date limits on Date Picker Dialog,in Android