替换字符,如替换全部(字符串,开始,结束,"_","-")
Replace chars like replaceAll(string, start, end, '_', '-')
我想将字符串text=s_o_m_e=text
替换为text=s-o-m-e=text
我有一个开始和结束索引:
std::string str("text=s_o_m_e=text");
std::string::size_type start = str.find("text="), end;
if (start != std::string::npos) {
end = str.find("=", start);
if (end != std::string::npos) {
//...
}
}
所以,我正在寻找这样的函数:
replaceAll(string, start, end, '_', '-');
向上:
std::replace(str.begin() + start, str.begin() + end, '_', '-');
谢谢,高炉
<algorithm>
中有一个函数。
std::replace(str.begin(), str.end(), '_', '-');
使用 std::replace
.以下是更多详细信息。
相关文章:
- 模板参数替换失败,并且未完成隐式转换
- 如何用转义符替换字符串中的所有特殊字符
- 为什么在这个代码结束循环中没有得到结束
- 试图对缓存进行跨步测试,但程序并没有结束
- 当调用switch语句中的函数时(即使函数不包含循环),似乎是永不结束的循环的问题
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- 在一个读写器队列中,我可以用volatile替换原子吗
- 用符号版本替换对函数的所有调用
- 为什么擦除方法会影响结束方法
- 根据用户输入用字母填充矢量,并将"开始"和"结束"放在四肢
- 如何通过替换顺序代码的while循环来添加OpenMP for循环
- 替换基于地图的所有引用
- 按平均值替换数组中的元素
- 删除映射和分割错误中的一个过去结束元素
- 我可以在这里替换什么,因为我不能在 C# 中使用隐式变量的 lambda 函数?
- 如何将字节数组元素替换为修改的十六进制 ASCII 符号?
- std::字符串在开始和结束之间替换
- 替换字符,如替换全部(字符串,开始,结束,"_","-")
- QT:如何从服务器替换JSON中的数字(开始,结束)
- 结束while循环进行字符替换