Rails: How to downcase non-English string?

Misha Moroshko picture Misha Moroshko · Sep 11, 2011 · Viewed 13.1k times · Source

How could I downcase a non-English string in Ruby on Rails 3 ?

str = "Привет"    # Russian 
puts str[0].ord   # => 1055
str.downcase!
puts str[0].ord   # => 1055 (Should be 1087)

I want it to work in Ruby 1.8.7 as well as Ruby 1.9.2.

Answer

fl00r picture fl00r · Sep 11, 2011
str = "Привет"
str.mb_chars.downcase.to_s
#=> "привет"