我正在尝试找出两个不同字符之间的子字符串。该字符串看起来像:
channelBlock_0\d_off_mux=8, 8, 8, 8, 8, 8, 8, 8
channelBlock_0\d_selvth=true, true, true, true, true, true, true, true
我想在 '='
之后和第一个 ','
之前进行拆分
在'='
之后进行切割已经对我有用......这就是我得到的:
std::string line; //contains the string from above
std::string startDel = "=";
std::string endDel = ",";
cout << line.substr(line.find(startDel)+1,line.find(endDel));
我的输出如下所示:
8, 8, 8, 8, 8, 8, 8, 8
true, true, true, true, true
我怎样才能在第一个“,”之后剪切,这样我的输出就是
8
true
最佳答案
检查后substring()
,你可以看到你需要的是:
line.substr(line.find(startDel) + 1, line.find(endDel) - (line.find(startDel) + 1));
因为该方法的第二个参数指出:
len
Number of characters to include in the substring (if the string is shorter, as many characters as possible are used).
关于c++ - 剪切带有多个结束符的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46154873/