c++关于字符串的替换
来源:互联网 发布:阿里云备案拍照 编辑:程序博客网 时间:2024/05/17 23:31
在c Java语言中,有replace 这个函数,可以用于字符串替换,但是c++却没有类似的功能
str 要处理的字符串 pattern 要替换的字符串 dstPattern 替换成为的字符串 count 替换个数
#include <iostream>
#include <string>
using namespace std;
string m_replace(string str,string pattern,string dstPattern,int count=-1)
{
string retStr="";
int pos;
int szStr=str.length();
int szPattern=pattern.size();
int i=0;
int l_count=0;
if(-1 == count) // replace all
count = szStr;
for(i=0; i<szStr; i++)
{
pos=str.find(pattern,i);
if(std::string::npos == pos)
break;
if(pos < szStr)
{
std::string s=str.substr(i,pos-i);
retStr += s;
retStr += dstPattern;
i=pos+pattern.length()-1;
if(++l_count >= count)
{
i++;
break;
}
}
}
retStr += str.substr(i);
return retStr;
}
- c++关于字符串的替换
- PHP开发:关于特殊字符串的替换
- C++: 替换字符串里面的字符
- c语言实现字符串字串的替换
- linux c下的字符串正则替换
- [C]no2.字符串替换
- C字符串替换
- c 字符串替换
- C字符串替换函数
- C语言 字符串替换
- C语言替换字符串
- 字符串替换 c
- 字符串替换C语言
- c语言字符串替换
- 关于C里面宏替换的问题
- 关于C里面宏替换的问题
- 关于C里面宏替换的问题
- C语言字符串替换函数,字符串插入函数的实现
- 第十六周项目三用函数指针调用函数
- hdu 4406 GPA 费用流
- 第16周 项目2-用指针玩字符串(1)
- 23种设计模式-11-责任连模式
- Java浮点数为什么精度会丢失
- c++关于字符串的替换
- 解决https证书导入路径有空格问题
- 第16周项目3-用函数指针调用函数
- 04分布式NOSQL HBASE - HBase过滤器
- 16周(oj 3)
- hdu 4309 Seikimatsu Occult Tonneru 枚举+最大流
- Spring使用入门示例
- Linux7运维视频教程
- 欧姆定律对电流精确测量造成的缺憾及解决方案