[代碼片段] 字符串替換

void replace(string& orignStr, const string& oldStr, const string& newStr) {
    size_t pos = 0;
    string::size_type newStrLen = newStr.length();
    string::size_type oldStrLen = oldStr.length();
    while (1) {
        pos = orignStr.find(oldStr, pos);
        if (string::npos == pos)
            break;
        orignStr.replace(pos, oldStrLen, newStr);
        pos += newStrLen;
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章