ooolky / NoteBook

0 stars 0 forks source link

c++ - 字符串替换内容 #132

Open ooolky opened 6 months ago

ooolky commented 6 months ago
std::string::size_type n = 0;
while ((n = result.find("main", n)) != std::string::npos) {
    result.replace(n, 4, "sub");
    n += 3; // 移动到替换字符串之后,避免无限循环
}