How to remove all instances of the pattern from a string?
string str = \"red tuna, blue tuna, black tuna, one tuna\";
string pattern = \"tuna\";
This is the basic logic for better understanding Here is the code in c++
string s,x; //s is the string , x is the substring
int a,l;
cin>>s>>x;
l=x.length();
while(true)
{
a=s.find(x);
if(a==-1)
{break;} // if substring is not found
else
{
s.erase(a,l); //if substring is found
}
}
if(s.length()==0) // if string length becomes null printing 0
cout<<0<<"\n";
else
cout<
example: input-shahaha output-shha