[Haskell-cafe] Reversing a string of words: C# v Perl V Ruby v
Haskell
Bernie Pope
bjpop at csse.unimelb.edu.au
Sun Dec 10 08:58:35 EST 2006
On 10/12/2006, at 10:50 PM, Andrew Savige wrote:
>
> A popular C# approach goes something like:
>
> private static string reverseWords(string str) {
> string[] words = Array.FindAll<string>(str.Split(
> new char[] {' ','\t'}),
> delegate(string s) {
> return !String.IsNullOrEmpty(s); });
> int i = words.Length - 1;
> if (i < 0)
> return String.Empty;
> StringBuilder sb = new StringBuilder(words[i]);
> while (--i >= 0)
> sb.Append(' ').Append(words[i]);
> return sb.ToString();
> }
Yikes! There ought to be a law against public displays of C# which
are not accompanied by health warnings.
:-)
Cheers,
Bernie.
More information about the Haskell-Cafe
mailing list