std::string字符串中替换子串的函数
2008-01-23 19:50
357 查看
//std::string中替换子字符串的函数
#include <string>
void string_replace( std::string &strBig, const std::string &strsrc, const std::string &strdst )
{
std::string::size_type pos = 0;
std::string::size_type srclen = strsrc.size();
std::string::size_type dstlen = strdst.size();
while( (pos=strBig.find(strsrc, pos)) != std::string::npos )
{
strBig.replace( pos, srclen, strdst );
pos += dstlen;
}
}
#include <string>
void string_replace( std::string &strBig, const std::string &strsrc, const std::string &strdst )
{
std::string::size_type pos = 0;
std::string::size_type srclen = strsrc.size();
std::string::size_type dstlen = strdst.size();
while( (pos=strBig.find(strsrc, pos)) != std::string::npos )
{
strBig.replace( pos, srclen, strdst );
pos += dstlen;
}
}
相关文章推荐
- 字符串替换函数 基于std::string
- 问题:求两个字符串的最长公共子串。 要求:输入两个字符串,输出它们的最长公共子串,包括长度。 设计: 设计一个类 String,包括一个 len(字符串长度)和字符串指针 s。另有如下成员函数: ·
- java中String字符串的替换函数:replace与replaceAll的区别
- Java:String 字符串的替换函数 replace replaceAll replaceFirst
- string的字符串替换函数,类似于CString的Replace
- java中String字符串的替换函数:replace与replaceAll的区别
- string 字符串中含有子串函数
- C++基础-string截取、替换、查找子串函数
- java中String字符串的替换函数:replace与replaceAll的区别
- Java StringBuffer 字符串替换函数 replace
- Lua 字符串替换函数 string.gsub(s, pat, repl [, n])
- PHP - Manual手册 - CLXI. String 字符串处理函数 - str_replace用替换字符串替换所有出现的搜索字符串
- java中String字符串的替换函数:replace与replaceAll的区别
- Lua 字符串替换函数 string.gsub(s, pat, repl [, n])
- java中String字符串的替换函数:replace与replaceAll的区别
- C++基础-string截取、替换、查找子串函数
- nyoj 113 字符串替换 (string中替换函数replace()和查找函数find())
- 利用替换字符串的函数StringReplace删除字符串中指定的字符或字符串
- java中String字符串的替换函数:replace与replaceAll的区别
- java中String字符串的替换函数:replace与replaceAll的区别