本文主要是介绍boost::string_algo详解4——trim_if,trim_copy_if,trim_xxxx_if,trim_xxxx_copy_if,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
函数的部分原型
- template<typename SequenceT, typename PredicateT>
- void trim_if(SequenceT & Input, PredicateT IsSpace);
- template<typename OutputIteratorT, typename RangeT, typename PredicateT>
- OutputIteratorT
- trim_copy_if(OutputIteratorT Output, const RangeT & Input,
- PredicateT IsSpace);
- template<typename SequenceT, typename PredicateT>
- SequenceT
- trim_copy_if(const SequenceT & Input, PredicateT IsSpace);
- template<typename SequenceT, typename PredicateT>
- void trim_left_if(SequenceT & Input, PredicateT IsSpace);
- template<typename OutputIteratorT, typename RangeT, typename PredicateT>
- OutputIteratorT
- trim_left_copy_if(OutputIteratorT Output, const RangeT & Input,
- PredicateT IsSpace);
- template<typename SequenceT, typename PredicateT>
- SequenceT
- trim_left_copy_if(const SequenceT & Input, PredicateT IsSpace);
例子
- void test_string_trim_if()
- {
- std::string str = "abcd!@#$%^efghi1234xyz";
- std::string str1 = boost::trim_left_copy_if(str, boost::is_alnum());
- assert(str1 == "!@#$%^efghi1234xyz");
- std::string str2 = boost::trim_right_copy_if(str, boost::is_alnum());
- assert(str2 == "abcd!@#$%^");
- std::string str3 = boost::trim_copy_if(str, boost::is_alnum());
- assert(str3 == "!@#$%^");
- boost::trim_left_if(str, boost::is_alnum());
- assert(str == "!@#$%^efghi1234xyz");
- boost::trim_right_if(str, boost::is_alnum());
- assert(str == "!@#$%^");
- // 如果是二元函数,可以做如下处理
- std::string str2nd("###GoodBye ChongQing!######");
- boost::trim_if(str2nd, bind2nd(std::equal_to<char>(), '#'));
- assert(str2nd == "GoodBye ChongQing!");
- // 当然用下面的方法也可以实现如上的功能
- std::string strAny("###Hello Fuzhou!######");
- boost::trim_if(strAny, boost::is_any_of("#"));
- assert(strAny == "Hello Fuzhou!");
- }
这篇关于boost::string_algo详解4——trim_if,trim_copy_if,trim_xxxx_if,trim_xxxx_copy_if的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!