Reputation: 35
i´m trying to figure out a substring between two different characters. the string looks like:
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
i want to split after the '='
and before the first ','
cutting after '='
already works for me... here´s what i got:
std::string line; //contains the string from above
std::string startDel = "=";
std::string endDel = ",";
cout << line.substr(line.find(startDel)+1,line.find(endDel));
my output looks like this:
8, 8, 8, 8, 8, 8, 8, 8
true, true, true, true, true
how can i cut after the first ',' so my output is just
8
true
Upvotes: 2
Views: 52
Reputation: 73366
After checking substring()
, you can see that what you need is:
line.substr(line.find(startDel) + 1, line.find(endDel) - (line.find(startDel) + 1));
since the second argument of the method states:
len
Number of characters to include in the substring (if the string is shorter, as many characters as possible are used).
Upvotes: 2