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 "trim_right_if" is used to remove all the trailing characters(specified by the boolean function to be written by the user) in the string i.e., it does condition based trimming on the right. Check out the examples below:
1. Removing "#" symbols:
Original String: "Hello nice to meet you####"
Modified String: "Hello nice to meet you"
2. Removing "@" symbols:
Original String: "@@@@You are using boost@@"
Modified String: "@@@@You are using boost"
input : an input sequence predicate : a function which determines what character(s) to trim.
The user has to write a function explicitly (that returns a boolean value) that specifies the character that the user wishes to trim.
The modification of the string is done in-place if trim_right_if() is used. There is another variation present i.e., trim_right_copy_if() , which takes the same parameters as input, but instead of modifying the string in-place it returns a copy of the modified string while keeping the original string as it is.
using namespace std;
using namespace boost::algorithm;
bool isAt(char c)
string s1 = "@@Welcome to boost@@";
string s2 = "You are using boost@@";
string s3 = "its very interesting@@@";
string newString = trim_right_copy_if(s3,isAt);
cout<<"Original String: "<<s3<<endl;
cout<<"Modified String: "<<newString<<endl;
As we can observe from the above code that trim_right_if() takes any string as input and it removes all the leading "@" symbols . It leaves the rest of characters and symbols untouched.
Similarly, trim_right_copy_if() instead of modifying the original string i.e., "s3", it returns the modified string to "newString".