惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
L
LangChain Blog
Jina AI
Jina AI
爱范儿
爱范儿
C
Check Point Blog
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
月光博客
月光博客
GbyAI
GbyAI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Stack Overflow Blog
Stack Overflow Blog
V
V2EX
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Microsoft Azure Blog
Microsoft Azure Blog
The GitHub Blog
The GitHub Blog
博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题

博客园 - 景天

[转]mysql sql 百万级数据库优化方案 left outer join Ext.extend 【转】C#中文排序(拼音和笔画) Ext中Checkbox的注意事项 - 景天 - 博客园 表单从服务器端读取 [转]关于project2003中几个视图的认识 Oracle 常用数据字典、外键查询 Oracle 10 回收站 ASP.NET MVC beta 模板(Templates) 中文修正补丁 完整版 Oracle备份数据库的脚本 RadioButtonList的选择确认 Oracle10g常用命令 和 常用函数 Oracle 10g 笔记1 连接和SQL编写 .NET调用Oracle存储过程,使用数组类型的参数(如ArrayList) Oracle 存储过程 及 .net 调用 按钮事件 直接下载 任何文件格式 ASP.NET MVC beta 中文模板修正补丁 IE7\IE6 图片上传预览 - 景天 - 博客园
C++ 字符串替换
景天 · 2009-02-07 · via 博客园 - 景天

#include   <string>   
  #include   
<iostream>   
    
  
using   namespace   std;   
    
  
string&   replace_all(string&   str,const   string&   old_value,const   string&   new_value)   
  {   
  
while(true)   {   
  
string::size_type   pos(0);   
  
if(   (pos=str.find(old_value))!=string::npos   )   
  str.replace(pos,old_value.length(),new_value);   
  
else   break;   
  }   
  
return   str;   
  }   
    
  
string&   replace_all_distinct(string&   str,const   string&   old_value,const   string&   new_value)   
  {   
  
for(string::size_type   pos(0);   pos!=string::npos;   pos+=new_value.length())   {   
  
if(   (pos=str.find(old_value,pos))!=string::npos   )   
  str.replace(pos,old_value.length(),new_value);   
  
else   break;   
  }   
  
return   str;   
  }   
    
  
int   main()   
  {   
  cout   
<<   replace_all(string("12212"),"12","21")   <<   endl;   
  cout   
<<   replace_all_distinct(string("12212"),"12","21")   <<   endl;   
  }   
    
  
//output:   
  
//22211   
  
//21221