0

In java if I say:

String input = "3, 4, 5,,"
String[] s = input.split(",", -1)

The output should look like: '3'; ' 4'; ' 5'; ''; ''; Which is 5 symbols length.

Currently from what I see from the Internet the functions usually split up to the '5' [which does what a normal split, without the -1 does] and terminate as they don't think the last comma in the end means a empty character as well as the empty char following it, simply because after the last comma there is no another enclosing coma. Indeed even a space does not work.

Can you please hint me a good tested method which already works or I will have to write my own parser?

KDX2
  • 945
  • 2
  • 14
  • 31
  • `boost::algorithm::split` is what I usually use. | https://stackoverflow.com/questions/9435385/split-a-string-using-c11 https://stackoverflow.com/questions/5167625/splitting-a-c-stdstring-using-tokens-e-g ... – Dan Mašek Nov 27 '18 at 21:12
  • Are you interested in saving the spaces too (5 `string`s: `"3 ", "4 ", "5 ", "", ""`)? – Bob__ Nov 27 '18 at 21:19
  • No, the spaces are not important. I will reread again but in the boost library I don't see an analogous version of split(, -1). – KDX2 Nov 27 '18 at 21:26

0 Answers0