c++ split string by double newline -
i have been trying split string double newlines ("\n\n"
).
input_string = "firstline\nsecondline\n\nthirdline\nfourthline"; size_t current; size_t next = std::string::npos; { current = next + 1; next = input_string.find_first_of("\n\n", current); cout << "[" << input_string.substr(current, next - current) << "]" << endl; } while (next != std::string::npos);
gives me output
[firstline] [secondline] [] [thirdline] [fourthline]
which not wanted. need like
[first line second line] [third line fourthline]
i have tried boost::split
gives me same result. missing?
find_first_of
looks single characters. you're telling passing "\n\n"
, find first of either '\n'
or '\n'
, , that's redundant. use string::find
instead.
boost::split
works examining 1 character @ time.
Comments
Post a Comment