Reputation: 3291
I am writing a Java server that takes data from another server. Unfortunately, part of the string it throws out is not able to be 'parsed' by the program. System.out.print
prints it as a question mark ?
This wretched question mark symbol cannot be parsed by my client's JSON parser either. Does anyone know how I can remove it?
Trying str.replace
with the ?
symbol didn't work.
Upvotes: 2
Views: 775
Reputation: 3291
Okay this worked for me:
stringName.replaceAll("[^\\x00-\\x7F]", "");
This was from some answer in stackoverflow but I can't find it now.
Upvotes: 2
Reputation: 22261
It looks like an encoding problem. Your application uses one encoding, while the server uses other.
Using the Charset
class will be your answer. Use it when converting received data to String. Most probably you'll have to specify it in a Reader
constructor, though I can't say without any code.
Here is the link to appropriate javadoc: InputStreamReader(InputStream, Charset)
Upvotes: 4