C++替换字符

来源:互联网 发布:logback 不打印sql 编辑:程序博客网 时间:2024/06/06 10:38

直接上代码:

void StringReplace(string &strBase, string strSrc, string strDes){string::size_type pos = 0;string::size_type srcLen = strSrc.size();string::size_type desLen = strDes.size();pos = strBase.find(strSrc, pos);while ((pos != string::npos)){strBase.replace(pos, srcLen, strDes);pos = strBase.find(strSrc, (pos + desLen));}}

其中strSrc为源字符,strDes是你想要替换成的字符。

0 0