trim_if():
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_if" is used to remove all the leading and 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 start and end of the string. Check out the examples below:
Examples:
1. Removing "#" symbols:
Original String: "####Hello nice to meet you###"
Modified String: "Hello nice to meet you"
2. Removing "@" and "$" symbols:
Original String: "@@@@You are using boost$$"
Modified String: "You are using boost"
header file:
boost/algorithm/string.hpp
syntax:
trim_if(input ,predicate);
parameters:
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_if() is used.
There is another variation present i.e., trim_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.
Comments