We've expanded our news coverage and improved our search! Visit
oreilly.com for the latest or search for all things across O'Reilly!
| Hack: |
|
Avoid the dreaded replaceAll method
|
| Subject: |
|
RE: Avoid the dreaded replaceAll method |
| Date: |
|
2006-08-07 09:25:07 |
| From: |
|
npgall
|
Response to: RE: Avoid the dreaded replaceAll method
|
|
Java 5 adds workarounds for this issue:
New method String.replace(CharSequence, CharSequence)
is a drop-in fix for replaceAll which performs a literal replacement. (A String is a CharSequence)
To performa literal replaceFirst, use:
s.replaceFirst(Pattern.quote("text to replace"), Matcher.quoteReplacement("replacement text"));
|