using String.replaceAll or replaceFirst to replace a string with special characters or symbols

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

If you have a string for example like this

With Java’s String.replaceAll or String.replaceFirst it will assume the string is in a regular expression format.

The way to avoid this to use is to use:
import java.util.regex.Pattern;
sb.toString().replaceFirst(Pattern.quote(“), “”);

Leave a Reply

Your email address will not be published. Required fields are marked *