#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;
}
/*
输出如下:
22211
21221
*/
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有