This function is included in the "boost/algorithm/string" library. This library contains some brilliant methods which help in accomplishing string manipulations that are lacking in STL library.
This function is used to remove all the instances of the specified pattern in the input string. It first performs a search for all the occurences of the specified pattern and then it erases it from the input string.
input_string : an input string
seacrh_string : the pattern that has to be replaced in the input_string;
erase_all() performs an inplace removal. There is another variation present erase_all_copy() which instead of doing an inplace removal, returns a copy of the modified string.
erase_all() performs a case-sensistive search. There is another variation present ierase_all() which performs a case-insensitive search. Similarly ierase_all_copy() returns a copy of modified string instead of doing an inplace removal.
using namespace std;
using namespace boost::algorithm;
string str1 = "Hello and Welcome Hello and Welcome";
string str2 = "Apple Banana Mango Apple Banana Apple";
string str4 = "Hi Hi Hi Hi Hi Hi";
string str3 = erase_all_copy(str4,"Hi ");
As we can observe from the output we are first performing an inplace removal where we are removing all the occurences of "Hello " with "Hi" . Next we are performing replacement on the original string while performing the search case-insensitively. In str3, we are storing the string obtained after performing replacement while searching case-sensitively. In the str3 we can observe that the last "Hi" is not replaced as the search string we are providing is "Hi "(along with a trailing whitespace).