Posted on 2010-01-11 19:10
S.l.e!ep.¢% 閱讀(2620)
評論(0) 編輯 收藏 引用 所屬分類:
C++
std::string 居然沒有 CString 的 replace 函數,? 不爽,網上找了一個
int replace_all(std::string& str,? const std::string& pattern,? const std::string& newpat)
{
?int count = 0;
?const size_t nsize = newpat.size();
?const size_t psize = pattern.size();
?
?for(size_t pos = str.find(pattern, 0);?
?pos != std::string::npos;
?pos = str.find(pattern,pos + nsize))
?{
??str.replace(pos, psize, newpat);
??count++;
?}
?
?return count;
}