Is there a simple way of using Guavas Splitter to split a string and retain the delimiters without using regex?
Something like
String string = "1+2-3*40";
Splitter splitter = Splitter.on(CharMatcher.DIGIT.negate()).retainDelimiters();
That gives
[1, +, 2, -, 3, *, 40]
I know about Splitter.onpattern() but that would require I give it a regular expression (yet thats what am trying to avoid).
I don't think it can be done in Guava now but you may submit a feature request. BTW what would be the output for "1+3**2"
? I think pattern would be unambiguous here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With