I have an Unicode string and need to translate it into pure ASCII.
t = "xf0x9dx97x94xf0x9dx98x82xf0x9dx97xb4xf0x9dx98x82xf0x9dx98x80xf0x9dx98x81"
My first try was unsuccessful:
t.encode('ASCII', invalid: :replace, undef: :replace, replace: '')
=> ""
Translated the string using unicode normalization:
t.unicode_normalize :nfkd
=> "August"
Is there a better solution? It should be gem-independent and work with Ruby 2.x (String#unicode_normalize
is unavailable on 2.1 and earlier versions).