C++实现字符串替换的两种方法
2015-03-31 20:04
681 查看
2013-06-09 13:43
5796人阅读 评论(0)
收藏
举报
替换字符串replace() erase()
5796人阅读 评论(0)
收藏
举报
替换字符串replace() erase()
//C++ 第一种替换字符串的方法用replace()|C++ 第二种替换字符串的方法用erase()和insert()【 C++[b]string|C++ replace()|C++ erase()|C++ insert()|C++自定义替换字符串函数】 [/b] #include<string> #include<iostream> using namespace std; //第一种替换字符串的方法用replace() void string_replace(string&s1,const string&s2,const string&s3) { string::size_type pos=0; string::size_type a=s2.size(); string::size_type b=s3.size(); while((pos=s1.find(s2,pos))!=string::npos) { s1.replace(pos,a,s3); pos+=b; } } //第二种替换字符串的方法用erase()和insert() void string_replace_2(string&s1,const string&s2,const string&s3) { string::size_type pos=0; string::size_type a=s2.size(); string::size_type b=s3.size(); while((pos=s1.find(s2,pos))!=string::npos) { s1.erase(pos,a); s1.insert(pos,s3); pos+=b; } }
相关文章推荐
- C++实现字符串替换的两种方法
- 【C/C++开发】C++实现字符串替换的两种方法
- C++实现字符串替换的两种方法
- C++字符串替换函数具体实现方法详解
- C++实现将一个字符串中的字符替换成另一个字符串的方法
- "找出字符串中第一个不重复的字符"和"找出字符串中最后一个重复的字符"的两种方法的C++实现
- C/C++/VC 实现字符串逆转的多种方法
- Perl从文件中读取字符串的两种实现方法
- Sql字符串分组Split函数的两种实现方法(转)
- C++ 在尾部添加字符串(两种方法) |C++ 连接字符串
- C++实现字符串替换
- js去除重复字符串两种实现方法
- 用c++实现类似vb的replace字符串替换
- C++输入一个字符串,把其中的字符按照逆序输出的两种方法
- 两种方法实现了左旋字符串
- C语言现代方法之实现字符串的替换
- Sql字符串分组Split函数的两种实现方法(转)
- 浮点性(float)转化为字符串类型 自定义实现和深入探讨C++内部实现方法
- Sql字符串分组Split函数的两种实现方法(转)
- C++实现的文本字符串替换功能