Balu
Balu

Reputation: 41

Remove special Unicode characters from a Java String

I am converting HTML data (data with bullet styling) to Java String, but we are getting junk values (�� - default Unicode value replaced) in the String, I tried to remove these values using replaceAll() but it's not working.

Any suggestions about how to remove these Unicode characters from the String?

Upvotes: 1

Views: 1066

Answers (1)

Helder Pereira
Helder Pereira

Reputation: 5756

You can remove all non-ASCII characters with:

s.replaceAll("[^\\p{ASCII}]", "")

Upvotes: 2

Related Questions