Archive

Posts Tagged ‘Text Encoding’

Character Encoding in Ruby with ActiveSupport

May 18th, 2009

In rails environment the following works:

"àáâãäå".mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n,'').downcase.to_s

Outside of rails you might need to wrap your strings explicitly in a ActiveSupport::Multibyte::Chars object. The following for example:

ActiveSupport::Multibyte::Chars.new("àáâãäå").mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n,'').downcase.to_s

Software , ,