Quickest way to do this string op.

C

Carlos

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
 
T

Tassilo Horn

What's the quickest way to turn "BOCA RATON" into "Boca Raton"?

irb(main):006:0> str = "BOCA RATON"
irb(main):009:0> str.gsub!(/\w+/) { |s| s.capitalize }
=> "Boca Raton"
irb(main):010:0> str
=> "Boca Raton"

Hope this helps. But I'm not sure if that's the fastest way in meaning
of speed. At least it's the solution which crossed my mind first. ;-)

Regards,
Tassilo
 
P

pinki

I'm also new, but this might be another solution:

"BOCA RATON".split(' ').collect do |name| name.capitalize end.join(' ')

It's not the quickest way though..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top