• [BOOST] BOOST::String


    Boost::String
    #include <boost/algorithm/string.hpp>


    1. Header <boost/algorithm/string/case_conv.hpp>
    boost::to_upper(str1);//直接改变str1的值
    boost::to_lower(str1);
    string str2 = boost::to_lower_copy(str1);   //不改变str1的值,返回副本
    string str2 = boost::to_upper_copy(str1);   //不改变str1的值,返回副本


    2. Header <boost/algorithm/string/classification.hpp>
    Boost.StringAlgorithms 库提供了几个从字符串中删除单独字母的函数, 
    可以明确指定在哪里删除,如何删除。
    例如,可以使用函数 boost::algorithm::erase_all_copy() 从整个字符串中 删除特定的某个字符。 
    如果只在此字符首次出现时删除,可以使用函数 boost::algorithm::erase_first_copy() 。 
    如果要在字符串头部或尾部删除若干字符,可以使用函数 boost::algorithm::erase_head_copy() 和 boost::algorithm::erase_tail_copy() 。


    3. Header <boost/algorithm/string/trim.hpp>
    boost::algorithm::trim_copy_if(str1, boost::algorithm::is_digit())  //删除首位所有的数字
    trim_left_copy
    trim_left_copy_if
    trim_right_copy
    trim_right_copy_if
    trim
    trim_if
    #trim_if# 
    inline void trim_if(SequenceT& Input, PredicateT IsSpace)
    可自定义谓词 "predicate"
    //删除'空格' 和 '0-5'
    bool foo2(const char& h)

        bool ret = false;
        if(h==' ' || (h>='0' && h<='5'))
        {
            ret = true;
        }
        return ret;
    }
    cout << boost::algorithm::trim_left_copy_if(str1, foo2) << endl;


    4. Header <boost/algorithm/string/classification.hpp>
    is_classified(std::ctype_base::mask Type, const std::locale& Loc=std::locale())
    is_space(const std::locale& Loc=std::locale())
    is_alnum(const std::locale& Loc=std::locale())
    is_alpha(const std::locale& Loc=std::locale())
    is_cntrl(const std::locale& Loc=std::locale())
    is_digit(const std::locale& Loc=std::locale())
    is_graph(const std::locale& Loc=std::locale())
    is_lower(const std::locale& Loc=std::locale())
    is_print(const std::locale& Loc=std::locale())
    is_punct(const std::locale& Loc=std::locale())
    is_upper(const std::locale& Loc=std::locale())
    is_xdigit(const std::locale& Loc=std::locale())
    is_any_of( const RangeT& Set )
    inline detail::is_from_rangeF<CharT> is_from_range(CharT From, CharT To)


    5. Header <boost/algorithm/string/compare.hpp>
    namespace boost {  
    namespace algorithm {
        struct is_equal;
        struct is_iequal;    
        struct is_less;    
        struct is_iless;
        struct is_not_greater;    
        struct is_not_igreater;  
       }
    }
    bool operator()(const T1 &, const T2 &) const;


    6. Header <boost/algorithm/string/erase.hpp>
    OutputIterator erase_range_copy (OutputIterator, Input, SearchRange);
    Sequence erase_range_copy (Input, SearchRange); 
    void erase_range (Input, SearchRange);
    删除输入字符串中SearchRange那部分。SearchRange是一个iterator_range对象。
    iterator_range( Iterator Begin, Iterator End )
    //删除s[0]-s[4]的字串
    cout << boost::algorithm::erase_range_copy(str1, boost::make_iterator_range(str1.begin(), str1.begin()+5)) << endl;
    boost::algorithm::trim_copy_if(str1, boost::algorithm::is_from_range('1', '5'));//删除'1'-'5'的字串


  • 相关阅读:
    HDU1050
    POJ3528移石头
    CodeForces230A
    lca学习题
    rmq的st算法模板题 nyoj 119
    rmq问题和lca可以相互转化
    rmq算法,利用倍增思想
    poj 1274 基础二分最大匹配
    hdu 1520 树形dp入门题
    poj 1466 最大独立集
  • 原文地址:https://www.cnblogs.com/bouygues/p/4479994.html
Copyright © 2020-2023  润新知