C++ boost::algorithm::string::ends_with()

C++ boost::algorithm::string::ends_with()


     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 check whether the end of a given string is same as the given pattern, i.e., checks whether the test string(pattern) is the suffix of the given input string. In other words it checks if the input ends with the test string or not.

header file:





    input : an input string(sequence)

    test : a test string(sequence)

The given function is case sensitive, i.e., it does the check case sensitively. For example, "applE" is not same as "apple"

 There is another variation present i.e., iends_with() , which takes the same parameters as input, but instead of doing a case sensitive test, it ignores the case of the characters and does the check, i.e., it does the check case insensitively. For example, "applE" is same as "apple".



using namespace std;
using namespace boost::algorithm;

int main()
//Input strings
string str[] = {"Welcome","You are using BOOST","its very interestING ","IT is very EffectivE"};

//Test strings
string test[] = {"ome","boost","ING ","effective"};

//performing the checks and printing the results with ends_with
cout<<"Using ends_with()"<<endl<<endl;
for(int i=0;i<4;i++)
cout<<str[i]<<" is checked with "<<test[i]<<endl;
cout<<"Result : The string ends with test- "<<ends_with(str[i],test[i])<<endl<<endl;

//performing the checks and printing the results with iends_with
cout<<"Using iends_with()"<<endl<<endl;
cout<<str[3]<<" is checked with "<<test[3]<<endl;
cout<<"Result : The string starts with test- "<<iends_with(str[3],test[3])<<endl;




In the above output, 1 means TRUE and 0 means FALSE.

As we can observe for str1 and str3 starts_with() returns TRUE and for str2 and atr4 it returns FALSE as the test string is "boost" and "effective" instead of "BOOST" and "EffectivE" respectively. (ends_with() does case sensitive check).

On the contrary, iends_with() return TRUE for str4 as it does case insensitive check.

More Articles of Md Safi Ur Rahman Khan:

Name Views Likes
C++ boost::algorithm::string::join() 577 0
C++ boost::algorithm::string::split() 607 0
C++ boost::algorithm::string::find_all() 646 0
C++ boost::algorithm::string::erase_tail() 249 0
C++ boost::algorithm::string::replace_tail() 211 0
C++ boost::algorithm::string::erase_head() 277 0
C++ boost::algorithm::string::replace_head() 209 0
C++ boost::algorithm::string::erase_all() 895 1
C++ boost::algorithm::replace_all() 2049 0
C++ boost::algorithm::string::erase_nth() 215 0
C++ boost::algorithm::string::replace_nth() 221 0
C++ boost::algorithm::string::replace_last() 246 0
C++ boost::algorithm::string::erase_last() 243 0
C++ boost::algorithm::string::erase_first() 215 1
C++ boost::algorithm::string::replace_first() 432 0
C++ boost::algorithm::string::find_token() 351 0
C++ boost::algorithm::string::find_tail() 200 1
C++ boost::algorithm::string::find_head() 212 0
C++ boost::algorithm::string::find_last() 300 1
C++ boost::algorithm::string::find_first() 749 1
C++ boost::algorithm::string::all() 224 1
C++ boost::algorithm::string::lexicographical_compare() 214 0
C++ boost::algorithm::string::equals() 378 0
C++ boost::algorithm::string::contains() 1822 0
C++ boost::algorithm::string::ends_with() 1283 0
C++ boost::algorithm::string::starts_with() 2058 0
C++ boost::algorithm::string::trim_if() 712 1
C++ boost::algorithm::string::trim() 3796 0
C++ boost::algorithm::string::trim_right_if() 522 1
C++ boost::algorithm::string::trim_left_if() 384 1
C++ boost::algorithm::string::trim_right() 282 3
C++ boost::algorithm::string::trim_left() 364 1
C++ boost::algorithm::string::to_lower() 736 1
C++ boost::algorithm::string::to_upper() 296 1
C++ Program to Implement Dequeue 1327 5
C++ Program to Implement Dequeue 241 3