Convert Å Ä Ö to A A O [duplicate]
Possible Duplicate:
How do I replace accented Latin characters in Ruby?
Is there an easy way to convert any letter that is not equal to a-z to a-z?
I want for example convert Ü
to U
, Ö
to O
and so on, I dont care about upper and lower case letters.
This is what I've so far.
{"ä" => "a", "å" => "a", "ö" => "o"}.each do |from, to|
string.gsub!(/#{from}/i, to)
end
But I don't want to specify every word.
Any ideas?
For a more general solution than String#tr
, look at the stringex gem. http://github.com/rsl/stringex
Use the tr method.
string.tr!( "äåö", "aao" );
精彩评论