From: "Iñaki Baz Castillo" Date: 2009-04-02T23:13:28+09:00 Subject: Re: String#capitalize more complex 2009/4/2 Iñaki Baz Castillo : > Is there any option even faster? I think it would be faster if I > operate directly in the original string instead of doing "split" and > "join" (since these last methods create more strings so allocate > memory for them and so). I would prefer to do the modification "in > place". > > BTW, could I know how to convert "a" char into "A"? I expected > something as in c: > >  'a' + 1 => 'b' >  'a' + ¿X? => 'A' I've done it in two ways: ----------------------------- require "benchmark" hname1 = "record-route" hname2 = "record-route" rt1=0.0 rt2=0.0 ### Method 1 1.upto(10) do rt1 += Benchmark.realtime { hname1 = hname1.split("-").map {|w| w.capitalize }.join("-") } end puts "hname1 = #{hname1} (time = #{rt1/10})" ### Method 2 1.upto(10) do i=0 rt2 += Benchmark.realtime do hname2.capitalize!.each_byte do |b| if b==45 && i