gpt4 book ai didi

c++ - 如何使用 std::string 用两个字符替换所有出现的一个字符?

转载 作者:IT老高 更新时间:2023-10-28 12:59:43 26 4
gpt4 key购买 nike

有没有一种很好的简单方法可以将 std::string 中所有出现的 "/" 替换为 "\/"转义 std::string?

中的所有斜杠

最佳答案

可能最简单的方法是使用 boost string algorithms library .

  boost::replace_all(myString, "/", "\\/");

std::string result = boost::replace_all_copy(myString, "/", "\\/");

关于c++ - 如何使用 std::string 用两个字符替换所有出现的一个字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5607085/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com