C++ 替换字符串

// 替换字符串的某一字符
std::string& replace_all(std::string& str, const std::string& old_value, const std::string& new_value)
{
    while (true) {
        std::string::size_type pos(0);
        if ((pos = str.find(old_value)) != std::string::npos)
            str.replace(pos, old_value.length(), new_value);
        else break;
    }
    return str;
}

 

posted on 2021-08-26 15:45  缘随风烬  阅读(1205)  评论(0编辑  收藏  举报