#include <iostream>

#include <string>

using namespace std;

/*

*  函数功能:将string字符串中的某些字符替换成其他字符

*  参数说明:  str 原字符串  strFind 需要替换字符串   strReplace 替换字符串

*/

string replace(string &str,const string &strFind,const string &strReplace)

{

int fsize = strFind.size();

int rsize = strReplace.size();

int pos = str.find(strFind,0);//从开始位置查找第一个符合的字符串,未找到返回str.npos

while (pos!=str.npos)

{

str.replace(pos,rsize,strReplace); //替换查找到的字符串

pos = str.find(strFind,pos+fsize); //继续查找

}

return str;

}

int main(int argc, char* argv[])

{

string str="abc[def[gef[ee[";

string strFind ="[";

string strReplace="(";

replace(str,strFind,strReplace);  //将字符串str中的“[”替换为“(”

cout<<str<<endl;

return 0;

}

最新文章

  1. 解决Tomcat无法shutdown进程
  2. Android Log介绍
  3. C++ 什么是句柄?为什么会有句柄?HANDLE
  4. php 基本符号
  5. Java NIO 缓冲技术详解
  6. Arduino 串口篇 Arduino发送十六进制 send HEX via serial port RS232-to-USB to PC
  7. WIN2003 设置 OPENVPN 服务端
  8. ERROR:&quot;org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /config/topics/test&quot; when creating or deleting Kafka operations authorized through the Ranger policies
  9. 外网访问内网SpringBoot
  10. 从vue源码看props
  11. Atitit 支出分类表 会计科目(1)资产(2)负债(3)资本(4)收益(5)费用(成本) 资产分类表 attilax总结
  12. UIScrollView _getDelegateZoomView bug 经历
  13. iftop 命令
  14. post与get的区别
  15. C# 抽签小程序
  16. vue02—— 动画、组件、组件之间的数据通信
  17. 20155224 2016-2017-2 《Java程序设计》第3周学习总结
  18. 【转载】OLE控件在Direct3D中的渲染方法
  19. Spring Bean作用域实例
  20. axios请求报Uncaught (in promise) Error: Request failed with status code 404

热门文章

  1. LightOJ-1236 Pairs Forming LCM 唯一分解定理
  2. 栈(stack)--c实现(使用双链表)
  3. MySQL 数据还原
  4. caioj 1157 线性筛选素数
  5. docker环境下mysql参数修改
  6. HDU 4069 数独
  7. ztree实现根节点右击事件,显示添加删除
  8. C - The C Answer (2nd Edition) - Exercise 1-12
  9. hadoop-11-ambari-server安装
  10. 程序员之---C语言细节12(指针和数组细节,&amp;quot;//&amp;quot;的可移植性说明)