开发者

Convert Å Ä Ö to A A O [duplicate]

This question already has answers here: 开发者_如何学运维 Closed 11 years ago.

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" );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜