This week's book giveaway is in the Game Development forum.
We're giving away four copies of Badass: Making Users Awesome and have Kathy Sierra on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes replace method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "replace method" Watch "replace method" New topic

replace method

Joseph Smithern
Ranch Hand

Joined: Feb 11, 2006
Posts: 89
For escaping form input quotes I have been using this:

Can I use something better like an ascii number or please advise?
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 41541
Do you mean String#replace(java.lang.CharSequence,%20java.lang.CharSequence)? Note that takes a CharSequence as its argument, not a regular expression like the replaceAll method. I think you are passing a regular expression.

I think you can use an ASCII value (well, Unicode) and you should find " in the "basic Latin" page here. You would use "\u1234" or '\u1234' depending whether you want it as a String or a char (or even (char)0x1234!). But you need to check carefully which method you are invoking. I don't think the replace method will allow you to delete the character.
StringBuilder does allow deletions, however.
I agree. Here's the link:
subject: replace method