From: "Iñaki Baz Castillo" Date: 2008-05-11T00:02:20+09:00 Subject: Re: "capitalize" also letters after "-" ? El Sábado, 10 de Mayo de 2008, Harry Kakueki escribió: > On Sat, May 10, 2008 at 10:52 PM, Iñaki Baz Castillo wrote: > > Hi, I receive strings like: > > > > content-language > > accept-resource-priority > > > > and I want to "capitalize" them in this way: > > > > Content-Language > > Accept-Resource-Priority > > > > But String#capitalize method just capitalized first letter: > > > > Content-language > > Accept-resource-priority > > > > > > Is there any "fast" method for what I want? > > Yes, I could implement it extending String class or my own class < > > String, but performance is very important and I'd prefer using a method > > written in C (as "String#capitalized"). Does is exist? > > > > > > Thanks a lot. > > > > > > -- > > Iñaki Baz Castillo > > Is this too slow? > > str = "accept-resource-priority" > p str.split(/-/).map {|x| x.capitalize}.join("-") Hummm: Benchmark.realtime { "accept".capitalize } => 2.21729278564453e-05 Benchmark.realtime { "accept".split('-').map {|w| w.capitalize}.join('-') } => 3.69548797607422e-05 -- Iñaki Baz Castillo