This is 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). You may assume that the remove string is length 1 or more. Remove only non-overlapping instances, so with "xxx" removing "xx" leaves "x".
withoutString("Hello there", "llo") → "He there"
withoutString("Hello there", "e") → "Hllo thr"
withoutString("Hello there", "x") → "Hello there"
=====================
and this is my answer :
====================Code:public String withoutString(String base, String remove) {
String r = remove.toLowerCase() ;
String b = remove.toUpperCase();
String res = "";
for(int i=0;i<base.length();i++){
int v = base.indexOf(r,i);
if(v<0) {
res+= base.substring(i, base.length());
break;
}else{
res += base.substring(i,v);
}
i = v+r.length()-1;
}
String fres = res;
String rr="";
for(int z=0;z<fres.length();z++){
int g = fres.indexOf(b,z);
if(g<0){
rr += fres.substring(z, fres.length());
break;
}else{
rr += fres.substring(z, g);
}
z = g+b.length()-1;
}
return rr;
}
and this is results :
withoutString("Hello there", "llo") → "He there" "He there" OK
withoutString("Hello there", "e") → "Hllo thr" "Hllo thr" OK
withoutString("Hello there", "x") → "Hello there" "Hello there" OK
withoutString("This is a FISH", "IS") → "Th a FH" "Th a FH" OK
withoutString("THIS is a FISH", "is") → "TH a FH" "TH a FH" OK
withoutString("THIS is a FISH", "iS") → "TH a FH" "TH a FH" OK
withoutString("abxxxxab", "xx") → "abab" "abab" OK
withoutString("abxxxab", "xx") → "abxab" "abxab" OK
withoutString("abxxxab", "x") → "abab" "abab" OK
withoutString("xxx", "x") → "" "" OK
withoutString("xxx", "xx") → "x" "x" OK
withoutString("xyzzy", "Y") → "xzz" "xzz" OK
withoutString("", "x") → "" "" OK
withoutString("abcabc", "b") → "acac" "acac" OK
other tests X
=======================
it say other tests are wrong ! what can be other tests?
