#include <boost/algorithm/string.hpp>            // for is_any_of
#include <boost/range/algorithm/replace_if.hpp> // for replace_if
#include <string>
#include <iostream> std::string someString = "abc.def-ghi";
std::string toReplace = ".-";
std::string processedString =
boost::replace_if(someString, boost::is_any_of(toReplace), ' '); int main()
{
std::cout << processedString;
}
This modifies the original, so if you need to keep it, you can use boost::replace_copy_if: #include <boost/algorithm/string.hpp>
#include <boost/range/algorithm/replace_copy_if.hpp>
#include <string>
#include <iostream>
#include <iterator> // for back_inserter std::string someString = "abc.def-ghi";
std::string toReplace = ".-"; int main()
{
std::string processedString;
boost::replace_copy_if(someString,
std::back_inserter(processedString), boost::is_any_of(toReplace), ' ');
std::cout << processedString;
}

replace_all_regex_copy

#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/regex.hpp> int main(int argc, char** argv) {
std::string someString = "abc.def-ghi";
std::cout << someString << std::endl;
std::string toReplace = "[.-]"; // character class that matches . and -
std::string replacement = " ";
std::string processedString =
boost::replace_all_regex_copy(someString, boost::regex(toReplace), replacement);
std::cout << processedString << std::endl;
return 0;
}

boost replace_if replace_all_regex_copy用法的更多相关文章

  1. boost::function的用法

    本片文章主要介绍boost::function的用法. boost::function 就是一个函数的包装器(function wrapper),用来定义函数对象. 1.  介绍 Boost.Func ...

  2. boost::bind 和 boost::function 基本用法

    这是一篇介绍bind和function用法的文章,起因是近来读陈硕的文章,提到用bind和function替代继承,于是就熟悉了下bind和function的用法,都是一些网上都有的知识,记录一下,期 ...

  3. [转] boost::any的用法、优点和缺点以及源代码分析

    boost::any用法示例: #include <iostream> #include <list> #include <boost/any.hpp> typed ...

  4. [boost] : asser库用法

    基本用法 需要包含头文件#include <boost/assert.hpp> assert库定义了两个断言宏 BOOST_ASSERT BOOSE_ASSERT_MSG 第一种形式等价于 ...

  5. boost bind function用法说明

    目录(?)[+] 1 bind/function 引 (1)头文件 bind函数#include <boost/bind.hpp> function使用头文件#include <bo ...

  6. (转)boost::bind介绍

    转自:http://www.cnblogs.com/sld666666/archive/2010/12/14/1905980.html 这篇文章介绍boost::bind()的用法, 文章的主要内容是 ...

  7. boost function对象

    本文根据boost的教程整理. 主要介绍boost function对象的用法. boost function boost function是什么 boost function是一组类和模板组合,用于 ...

  8. boost::function 介绍

    本片文章主要介绍boost::function的用法. boost::function 就是一个函数的包装器(function wrapper),用来定义函数对象. 1.  介绍 Boost.Func ...

  9. boost::bind 介绍

    boost::bind 介绍   这篇文章介绍boost::bind()的用法, 文章的主要内容是参考boost的文档. 1. 目的 boost::bind 是std::bindlist 和 std: ...

随机推荐

  1. Android(java方法)上实现mp4的分割和拼接 (二)

    这节谈一下如何在android上实现mp4文件的高效率切割. 业务需求举例:把一段2分钟的mp4文件切割出00:42 至 01:16这段时间的视频,要求足够短的执行时间和尽量少的误差. 分析:mp4P ...

  2. DICOM医学图像处理:深入剖析Orthanc的SQLite,了解WADO & RESTful API

    背景: 上一篇博文简单翻译了Orthanc官网给出的CodeProject上“利用Orthanc Plugin SDK开发WADO插件”的博文,其中提到了Orthanc从0.8.0版本之后支持快速查询 ...

  3. Solaris主机间的信任关系机制

    解决问题: 管理员经常在其他服务器之间登录,是否需要密码切换. 知识点:主机间信任关系.R 命令集 /etc/hosts/equiv 文件 R服务是不加密的,别人可以破解. 主机名 + 用户名. + ...

  4. mysql truncate table命令使用总结

    truncate使用注意 由于上过truncate table a_table命令一次当,将教训记录下来,以示警戒!     mysql truncate table a_table命令受影响结果说明 ...

  5. AtomicInteger在实际项目中的应用

    AtomicInteger.一个提供原子操作的Integer的类. 在Java语言中,++i和i++操作并非线程安全的.在使用的时候,不可避免的会用到synchronized关键字. 而AtomicI ...

  6. Spring学习【Spring概述】

    从本文開始,我们就要一起学习Spring框架,首先不得不说Spring框架是一个优秀的开源框架. 当中採用IoC原理实现的基于Java Beans的配置管理和AOP的思想都是非常值得学习与使用的.以下 ...

  7. PHP开发环境简析

    单工作机情况 windows + wamp windows + XShell类终端工具 + linux虚拟机 Ubuntu桌面版 自带终端 Mac OS + mamp Mac OS 自带终端 Mac ...

  8. Android 设计模式之单例模式

    设计模式是前人在开发过程中总结的一些经验,我们在开发过程中依据实际的情况,套用合适的设计模式,能够使程序结构更加简单.利于程序的扩展和维护.但也不是没有使用设计模式的程序就不好.如简单的程序就不用了, ...

  9. Webkit JNI

    WebCoreFrameBridge.cpp BrowserFrame通过jni传下来的调用都会调用到WebCoreFrameBridge.cpp中的对应函数中,其他webkit的模块想回调信息给Br ...

  10. JQGrid总记录数和查询消耗时间不显示

    其他做的几个页面都显示,只有一个不显示....百度发现, viewrecords选项未配置,应该设置为ture才可以.