in reply to Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)
Still in Java-dom, here's a version in Groovy:
def reverseWords( str ) { str.split('\\s+'). findAll {it.length() > 0}. reverse().join(' ') }
|
---|
In Section
Meditations