I need to remove some substrings in strings (in a large dataset). The substrings often contain special characters, like these: ., ^, /,... and replaceAll() would treat them as s
There are 2 methods named replace
in the String
class that perform replacement without treating their parameters as regular expressions.
One replace method replaces one char
with another char
.
The other replace method replaces a CharSequence
(usually a String
) with another CharSequence
.
Quoting the Javadocs from the second replace
method:
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.