# Quickest way to do this string op

**URL:** <https://www.ruby-forum.com/t/quickest-way-to-do-this-string-op/80336>\
**Category:** Ruby\
**Created:** [March 13, 2006, 2:25pm UTC](https://www.ruby-forum.com/t/quickest-way-to-do-this-string-op/80336 "2006-03-13T14:25:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 13, 2006, 2:25pm UTC](https://www.ruby-forum.com/t/quickest-way-to-do-this-string-op/80336/1 "2006-03-13T14:25:07Z")

</div>

What’s the quickest way to turn “BOCA RATON” into “Boca Raton”?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 13, 2006, 2:34pm UTC](https://www.ruby-forum.com/t/quickest-way-to-do-this-string-op/80336/2 "2006-03-13T14:34:31Z")

</div>

removed\_email\_address@domain.invalid wrote:

> What’s the quickest way to turn “BOCA RATON” into “Boca Raton”?

“BOCA RATON”.replace “Boca Raton” # 😛

Probably

“BOCA RATON”.split(/\b/).map{|s| s.capitalize }.join

It is quick to write, at least…

HTH

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 13, 2006, 3:20pm UTC](https://www.ruby-forum.com/t/quickest-way-to-do-this-string-op/80336/3 "2006-03-13T15:20:36Z")

</div>

removed\_email\_address@domain.invalid writes:

> 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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 13, 2006, 10:20pm UTC](https://www.ruby-forum.com/t/quickest-way-to-do-this-string-op/80336/4 "2006-03-13T22:20:29Z")

</div>

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…
