• Post Reply Bookmark Topic Watch Topic
  • New Topic

Replacing \\0020 in a string  RSS feed

 
Richard Scothern
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm processing some strings where someone has typed in a unicode character by hand e.g. "hello\u0020there". In Java this is represented as "hello\\u0020there". What I want to do is replace the "\u0020" text with a " ". However, when I use:
String s = "hello\u0020there";
s = s.replaceAll("\\u0020", " ");
I don't get the expected "hello there", in fact it doesn't change at all.
Does anyone know why this happens? I could write my own replacement method, but I'd prefer to find a more elegant solution.
Thanks,
Richard
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "replaceAll()" method uses regular expressions behind the scenes, and a back-slach (\) has special meaning. Try this:

Yes, you need all four back-slashes ...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!