View Problem

Reverse the words in a string

Given the string "This is a end, my only friend!", produce the string "friend! only my end, the is This"
ExpandDiskEdit
ruby
reversed = text.split.reverse.join(' ')
ExpandDiskEdit
erlang
Reversed = string:join(lists:reverse(string:tokens("This is the end, my only friend!", " ")), " "),
ExpandDiskEdit
csharp 3.0
var str = "This is a end, my only friend!";
str = String.Join(" ", str.Split().Reverse().ToArray());
Console.WriteLine(str);
ExpandDiskEdit
cpp C++/CLI .NET 2.0
array<Char>^ sep = {L' '};
array<String^>^ words =
String(L"This is the end, my only friend!").Split(sep, StringSplitOptions::RemoveEmptyEntries);

Array::Reverse(words); String^ newwords = String::Join(L" ", words);
ExpandDiskEdit
cpp
std::string words = "This is the end, my only friend!"; std::vector<std::string> swv;

boost::split(swv, words, boost::is_any_of(" ")); std::reverse(swv.begin(), swv.end());
std::string newwords = (std::for_each(swv.begin(), swv.end(), StringTAndJ())).value();
DiskEdit
clojure
(require '[clojure.contrib.str-utils2 :as str])
(str/join " " (reverse (str/split "this is the end, my only friend!" #" ")))
DiskEdit
clojure
(apply str (interpose " " (reverse (re-seq #"[^\s]+" "This is the end, my only friend!"))))

Submit a new solution for ruby, erlang, csharp, cpp ...
There are 20 other solutions in additional languages (fantom, fsharp, go, groovy ...)