Ed_ Ed_ - 4 months ago 18
Java Question

Guava CharMatcher remove whitespace retain linebreaks

Noob question, I need to split a string by many separators, and I want to delete all whitespaces, but Guava Charmatcher is removing linebreaks too (and linebreak is one of the separators):

Iterable<String> splittedRuts = Splitter.onPattern("\r?\n|,|/|;")


As long as you're ok with only removing the normal space character, you can just use CharMatcher.is(' ').

Also, you may want to look at Splitter.trimResults() if your reason for wanting to strip whitespace is that you end up with leading or trailing whitespace when splitting.