I\'m using the Twitter API and I have the following string that is bugging me Proyecto de ingeniera comercial, actual Profesora de matemáticas \\u0000\\u0000\\u0000\\u
The first argument to replaceAll
is a regular expression, and the Java regex engine understands \uNNNN
escapes so
json.replaceAll("\\u0000", "")
will search for the regular expression \u0000
, which matches instances of the Unicode NUL character (U+0000), not instances of the actual string \u0000
. If you want to match the string \u0000
then you need to use the regular expression \\u0000
, which in turn means the Java string literal "\\\\u0000"
json.replaceAll("\\\\u0000", "")
Or more simply, use replace
(whose first argument is a literal string rather than a regex) instead of replaceAll
json.replace("\\u0000", "")
string = string.replace("\u0000", ""); // removes NUL chars
string = string.replace("\\u0000", ""); // removes backslash+u0000
The character with u-escaping is done on java source level. For instance "class" is:
public \u0063lass C {
Also you do not need regex.