string StringTool::ReplaceAll(const string& str, const string& src, const string& des)
// 将字符串str中所有的字符串src替换成字符串des
{
string temp;
temp.reserve(str.size());
if (0 < src.length())
{
size_t pos = str.find(src);
size_t lastpos = 0;
while (pos != string::npos)
{
temp += str.substr(lastpos, pos - lastpos);
temp += des;
lastpos = pos + src.length();
pos = str.find(src, lastpos);
}
if (lastpos != str.length())
{
temp += str.substr(lastpos, str.length() - lastpos);
}
}
return temp;
}
作者:zilaishuichina
来源:优快云
原文:https://blog.youkuaiyun.com/zilaishuichina/article/details/53997103
版权声明:本文为博主原创文章,转载请附上博文链接!