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














































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



to_lower():
     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 "to_lower" is used to convert any given argument string to lower case. 
header file:
boost/algorithm/string.hpp
syntax:
     to_lower(input , loc);
parameters:
    input : an input range
    loc :  a locale used for conversion

    The modification of the string is done in-place if to_lower() is used.
    
    There is another variation present i.e., to_lower_copy() , 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.

SAMPLE CODE:

#include<iostream> #include<boost/algorithm/string.hpp> using namespace std; using namespace boost::algorithm; int main() { string s1,s2,s3,s4; s1 = "welcome to boost"; s2 = "ITS WRITTEN IN C++"; s3 = "#@ It'S QuItE iNtErEsTiNg **"; s4 = "AND ITS QUITE FUN TOO!!"; //converting the strings to lower case in-place to_lower(s1); to_lower(s2); to_lower(s3); //returning the modified string to newString string newString = to_lower_copy(s4); cout<<s1<<endl; cout<<s2<<endl; cout<<s3<<endl; cout<<"Original string :"<<s4<<endl; cout<<"Modified string :"<<newString<<endl; }

OUTPUT:


EXPLANATION:

As we an observe from the above code that to_lower() takes any string as input and irrespective of the case of the original characters, it formats them to lower case. It leaves the special characters and symbols untouched.
Similarly, to_lower_copy()  instead of modifying the original string i.e., "s4", it returns the modified string to "newString".



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() 1824 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() 737 1
C++ boost::algorithm::string::to_upper() 296 1
C++ Program to Implement Dequeue 1327 5
C++ Program to Implement Dequeue 241 3

Comments