Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java : Remove strange special characters from String [duplicate]

Tags:

java

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.

enter image description here

like image 878
psms Avatar asked Mar 01 '16 10:03

psms


People also ask

How do I remove a junk character from a string in Java?

You can use a regular expression and replaceAll() method of java. lang. String class to remove all special characters from String.

How do you skip special characters in Java?

Strings - Special Characters The solution to avoid this problem, is to use the backslash escape character.


2 Answers

You can use

String newString = my_string.replaceAll("\\p{C}", "");

more information about Java Unicode Regular expression Java Unicode Regular expression here

like image 190
Emdadul Sawon Avatar answered Oct 16 '22 04:10

Emdadul Sawon


This will work:

String string = yourString.replaceAll("[^\\x00-\\x7F]", "");
like image 28
Santosh Jadi Avatar answered Oct 16 '22 04:10

Santosh Jadi