字符串查找和替换接口

int replace_str(std::string& str, const char * oldpart, const char * newpart){intnReplaced= 0;std::string::size_type nIdx= 0;std::string::size_type nOldLen= strlen(oldpart);if ( 0 == nOldLen )return 0;static const char ch = 0x00;std::string::size_type nNewLen= strlen(newpart);const char* szRealNew= newpart == 0 ? &ch : newpart;while ( (nIdx=str.find(oldpart, nIdx)) != std::string::npos ){str.replace(str.begin()+nIdx, str.begin()+nIdx+nOldLen, szRealNew);nReplaced++;nIdx += nNewLen;}return nReplaced;

}

功能: 从str中查找oldpart, 并替换成newpart.

,并且如此真实的活着——这,就是旅行的意义。

字符串查找和替换接口

相关文章:

你感兴趣的文章:

标签云: