[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Quickest way to do this string op.

Kroeger, Simon (ext)

3/13/2006 1:34:00 PM



> -----Original Message-----
> From: Carlos [mailto:angus@quovadis.com.ar]
> Sent: Monday, March 13, 2006 2:31 PM
> To: ruby-talk ML
> Subject: Re: Quickest way to do this string op.
>
> eastcoastcoder@gmail.com wrote:
>
> > What's the quickest way to turn "BOCA RATON" into "Boca Raton"?
>
> "BOCA RATON".replace "Boca Raton" # :-P
>
> Probably
>
> "BOCA RATON".split(/\b/).map{|s| s.capitalize }.join
>
> It is quick to write, at least...
>
> HTH

"BOCA RATON".gsub(/\w+/){|w| w.capitalize}

is even shorter :)

cheers

Simon