This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java Ecscape character

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to replace the fist word to then second.

"dd" --> \"dd\"

I try s.replace('\"','\\\"'); It doesn't work.

How to do it ?

Thanks
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The backslash is special to both the Java compiler and the regexp parser, which means that to specify a real backslash in a regexp, you have to actually write four backslashes: Two of them (\\) are needed by the regexp, and then to get the Java compiler to parse those two, they have to be escaped, giving you four. So I believe your replacement expression ought to have five backslashes, total: "\\\\\"" .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic