先测试下风格

20924 /**************************************
20925 [liuzhuan]
20926 **************************************/
20927 std::string m_replace(std::string strSrc, const std::string &oldStr, const std::string &newStr, int count=-1){
20928 std::string strRet=strSrc;
20929 size_t pos = 0;
20930 int l_count=0;
20931 
20932 if(-1 == count){
20933 count = strRet.size();
20934 }
20935 
20936 while ((pos = strRet.find(oldStr, pos)) != std::string::npos){
20937 strRet.replace(pos, oldStr.size(), newStr);
20938 
20939 if(++l_count >= count)
20940 break;
20941 
20942 pos += newStr.size();
20943 }
20944 return strRet;
20945 }

 

posted on 2020-05-12 18:09  360~倒立扣篮  阅读(86)  评论(0编辑  收藏  举报

导航