Hi find your solution in c++ : https://ideone.com/I1Ic1j
where I used find and replace functions from string and if you want to implement it in java,it will be easy to implement with this solution.
#include <iostream>
#include<string>
using namespace std;
// To execute C++, please define "int main()"
int main() {
string str="Is it appropriate ans to your problem? : by queryhome",key="ho";
// cin>>str>>key;
size_t i = 0;
while (true) {
i = str.find(key, i);
if (i== std:: string ::npos)
{
break;
}
str.replace(i, key.length(),"");
i += 1;
}
cout<<str<<endl;
return 0;
}