首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

c++ std:string repalce字符串

2012-09-06 
c++ std::string repalce字符串//原字符串,要替换的字符串,替换为什么字符串str_replace(std::string & st

c++ std::string repalce字符串
//原字符串,要替换的字符串,替换为什么字符串
str_replace(std::string & str, 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 = str.find(strsrc,pos)) != std::string::npos)
{
str.replace(pos,srclen,strdst);
pos += dstlen;
}
}

热点排行