Ed_ Ed_ - 2 years ago 186
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|,|/|;")

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download