Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)

by eyepopslikeamosquito (Chancellor)
on Dec 12, 2006 at 12:27 UTC ( #589260=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download

  1. or download this
     "  one   two three four    "
  2. or download this
     "four three two one"
  3. or download this
     private static string reverseWords(string str) {
         string[] words = Array.FindAll<string>(str.Split(
             sb.Append(' ').Append(words[i]);
         return sb.ToString();
  4. or download this
     return String.Join(" ", words);
  5. or download this
     sub reverseWords {
         join ' ', reverse split(' ', shift)
  6. or download this
     sub reverseWords(Str $s) returns Str {
         $s.words.reverse.join(' ')
  7. or download this
     def reverseWords(s)
         s.split.reverse.join(' ')
  8. or download this
     reverseWords = unwords . reverse . words

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://589260]
Approved by Corion
Front-paged by grinder
jkva dusts the floor
[karlgoethebier]: Totally OT but my pleasure: Next week i'll have my first archery lesson.
[Corion]: Hi jkva!
[Corion]: karlgoethevier: Oooh, that sounds interesting! ;)
[karlgoethebier]: btw, good morning
[Happy-the-monk]: karlgoethebier: have fun! Did some archery at the age of 14 or so.
[karlgoethebier]: Corion: It is, indeed.
[Happy-the-monk]: even more OT: received the complete series of Robin Hood/Robin of Sherwood 1984 on used dvds this morning :)
[Happy-the-monk]: (purely coincidental)
[jkva]: Corion Hey there :)

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2017-10-20 09:56 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (260 votes). Check out past polls.