It's not a secret anymore!
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

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]
Have you checked out Aspose?
subject: java Ecscape character
It's not a secret anymore!