I have an invalid escape sequence inside a json string. The sequence is:
'ngram': "'s\xa0cancer prevention"
I have been trying to remove this sequence completely by replacing it with a blank string, however each attempt fails. I have tried the following ways:
qumlsOutputAsJson = qumlsOutputAsJson.replaceAll("[^\\x20-\\x7E]", "");
and
qumlsOutputAsJson = qumlsOutputAsJson.replaceAll("\\.", "");
and even a routine:
private String removeNonAscii(String text){
String asciiText = "";
for (char aChar: text.toCharArray()){
if((int)aChar<=0x7F)
asciiText = asciiText + Character.toString(aChar);
}
return asciiText;
}
All have failed.
I'm sure there is an obvious way, but any direction much appreciated.
With replaceAll you need to escape the backslash, i.e. "\\\\",""
If you just used replace, yours should work as expected
qumlsOutputAsJson = qumlsOutputAsJson.replaceAll("\\\\", "");
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