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 erase the first instance of the specified pattern in the input string. It first performs a search for the specified pattern and then removes it.
input_string : an input string
seacrh_string : the pattern that has to be erased from the input_string;
erase_first() performs an inplace removal. There is another variation present erase_first_copy() which instead of doing an inplace removal, returns a copy of the modified string.
erase_first() performs a case-sensistive search. There is another variation present ierase_first() which performs a case-insensitive search. Similarly ireplace_first_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 to boost";
string str2 = "It is NOT interseting";
string str3 = erase_first_copy(str1,"and ");
As we can observe from the output we are first performing an inplace removal where we are removing "Hello " . Next we are performing removal on the original string while performing the search case-insensitively. In str3, we are storing the string obtained after performing removal while searching case-sensitively.