Re: String replaceAll doesn't like commas



Jeffrey Schwab wrote:
O.B. wrote:
Why doesn't the following turn "Bubba, Inc." into "Bubba\, Inc."?

String test = "Bubba, Inc.";
test = test.replaceAll(",", "\\,");

The double quotes eat one backslash. The regex parser eats the other. Try "\\\\,".

It gets really fun when you want to quote backslashes in a string with an additional backslash:


someString.replaceAll("\\\\", "\\\\\\\\");

That's a lot of backslashes.
.