I want to remove all strange special characters from a string in Java. Those strange special characters are appearing in form of ?(Question mark) in MS Word.The image of sample string is given below.
You can use a regular expression and replaceAll() method of java. lang. String class to remove all special characters from String.
Strings - Special Characters The solution to avoid this problem, is to use the backslash escape character.
You can use
String newString = my_string.replaceAll("\\p{C}", "");
more information about Java Unicode Regular expression Java Unicode Regular expression here
This will work:
String string = yourString.replaceAll("[^\\x00-\\x7F]", "");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With