This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons 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: 24183

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:
subject: java Ecscape character
Similar Threads
Links for mock tests
listener class name addition in web.xml
instanceof issue
Five new mock questions for SCBCD beta