you can use
String result = base.replaceAll(remove,"");
With the quotation marks where you are trying, it actually tries to remove the "remove" .
To deal with the insenstive case, you can use the regex flag for the case of ignoring (?i) in front, after which you can call
String result = base.replaceAll("(?i)" + remove,"");
This means that String remove is now a regular expression, so special characters can have unwanted results. For example, if your line for deletion was . , you had to delete each character. If you do not want this to be like a regular expression, use
String result = Pattern.compile(remove, Pattern.LITERAL).matcher(base).replaceAll("")
Which may also include case insensitive flags, as they are a bitmask, see Pattern for more.
Pattern.LITERAL | Pattern.CASE_INSENSITIVE
EDIT
To do this using your loop, just do this loop
for (int i=0; i <= base.length()-remove.length(); i++) { if (base.substring(i, i+remove.length()).equals(remove)) { base = base.substring(0, i) + base.substring(i + remove.length() , base.length()); i--; } }
Java devil
source share