O
O.B.
Why doesn't the following turn "Bubba, Inc." into "Bubba\, Inc."?
String test = "Bubba, Inc.";
test = test.replaceAll(",", "\\,");
String test = "Bubba, Inc.";
test = test.replaceAll(",", "\\,");
O.B. said:Why doesn't the following turn "Alpha, Inc." into "Alpha\, Inc."?
String test = "Alpha, Inc.";
test = test.replaceAll(",", "\\,");
Stefan said:Why not just read about it in the documentation?
http://download.java.net/jdk6/docs/...eplaceAll(java.lang.String, java.lang.String)
At said:Why doesn't the following turn "Bubba, Inc." into "Bubba\, Inc."?
String test = "Bubba, Inc.";
test = test.replaceAll(",", "\\,");
O.B. said:Why doesn't the following turn "Bubba, Inc." into "Bubba\, Inc."?
String test = "Bubba, Inc.";
test = test.replaceAll(",", "\\,");
seeString test = "Bubba, Inc.";
test = test.replaceAll(",", "\\,");
What's wrong with my regular expression?
\\ is a magic character to regexes and in a magic character to Java
string literals. You have to "quote" it for both. The docs are not
clear unless you read up on Matcher.replaceAll, but he second parm is
a regex too, not just a simple string.
Jeffrey said:The double quotes eat one backslash. The regex parser eats the other.
Try "\\\\,".
Alan Krueger said:someString.replaceAll("\\\\", "\\\\\\\\");
That's a lot of backslashes.
Stefan said:{ return this.string.replaceAll
( java.util.regex.Pattern.quote( search ),
java.util.regex.Matcher.quoteReplacement( replace )); }}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.