I want to remove all weird special characters from a string in Java. Are these weird special characters appearing on the form ? (question mark) in MS Word. The following is an image of an example string.
String string=givenString.replaceAll("[^\\p{ASCII}]", "");
\ p {ASCII} are the POSIX character classes. It will replace the non ascii string and return the string (Printable ASCII).
This will work:
String string = yourString.replaceAll("[^\\x00-\\x7F]", "");
you can use
String newString = my_string.replaceAll("\\p{C}", "");
Learn more about Java Unicode. Java Unicode regex . Regex here