This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt 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 Introducing JavaFX 8 Programming this week in the JavaFX 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: 24193

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