I'm doing some beginner's coding practice and I ran into this problem:Given two strings, base and remove, return a version of the base string where all instances of the remove string have been removed. (not case sensitive).
This is what I have so far, but it's not working at all.
public String withoutString(String base, String remove) {
for (int i=0; i<base.length()-remove.length(); i++){
if (base.substring(i, i+remove.length()).equals(remove)){
base = base.substring(i, base.indexOf("remove")-1) + base.substring(base.indexOf("remove"), base.length()-remove.length());
}
}
return base;
}
I've yet to deal with the case sensitive part to make it more visible for myself. I'm also not sure why I can't use base.replaceAll("remove",""); Any help is appreciated.
EDIT*: I made a rookie mistake and the replaceAll still works. Additionally, how could I have done this using loops and conditionals? Would it have been messy like what I had previously?