c++的string本身没有字符串替换为另外一个字符串的功能,特此在这里添加一个替换函数
int CStringTool::Replace(std::wstring& strContent, std::wstring& strReplace, std::wstring & strDest)
{
while (true)
{
size_t pos = strContent.find(strReplace);
if (pos != std::wstring::npos)
{
WCHAR pBuf[1]={L'\0'};
strContent.replace(pos, strReplace.length(), pBuf, 0);
strContent.insert(pos, strDest);
}
else
{
break;
}
}
return 0;
}
本文介绍了一个用于C++中字符串替换的实用函数。该函数能够将std::wstring中的指定子串替换成另一个字符串,适用于需要频繁进行字符串操作的场景。
2976

被折叠的 条评论
为什么被折叠?



