c++字符串替代源码
来源:互联网 发布:解放军的无人机 知乎 编辑:程序博客网 时间:2024/06/01 20:55
#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;
}
#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;
}
0 0
- c++字符串替代源码
- c字符串函数源码
- C 字符串取代源码
- 常见C语言面试题之三:字符串替代
- format字符串替代变量
- 115,字符串替代
- 替代字符串的空格
- Java替代C语言
- 替代链接 extern “C”
- MFC中对C中字符串操作函数的替代函数
- StringBuilder替代字符串的连接"+"
- 截取字符串使用省略号替代
- c 字符串处理函数----strtok 源码
- C语言字符串函数源码详解
- C语言字符串处理函数源码
- c/c++字符串操作函数源码解析
- c 实现字符串反转(参考redis源码)
- C语言字符串相关操作及源码
- HTTP请求 GET POST 网络编程实现
- POJ 3321 Apple Tree(dfs+树状数组)
- 较老版本的AFNetworking使用心得
- 支付宝集成错误
- Ogre水面倒影的实现
- c++字符串替代源码
- bee框架学习笔记
- Spring MVC3在controller和视图之间传递参数的方法
- 循序渐进开发WinForm项目(4)--Winform界面模块的集成使用
- -------------Android判断应用或Activity的存在性
- pds 1112 bfs
- 机器人
- 找回丢失已久的输入法状态条
- ZOJ3471