This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes java Ecscape character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java Ecscape character" Watch "java Ecscape character" New topic

java Ecscape character

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
I want to replace the fist word to then second.

"dd" --> \"dd\"

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

How to do it ?

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

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: "\\\\\"" .

[Jess in Action][AskingGoodQuestions]
wood burning stoves
subject: java Ecscape character
It's not a secret anymore!