aspose file tools*
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
Author

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 ?

Thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java Ecscape character