[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'的字串


 

转载于:https://www.cnblogs.com/bouygues/archive/2013/01/04/4479994.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值