Currently I'm working on an Rails application with PayPal checkout. PayPal communicates with my app with IPN messages.
In many cases everything works fine, but if someone uses special chars like German umlauts (öüäß
) I get \xf6
in the string.
How can I convert this into the human readable char 'ö'
?
The problem is that the data was encoded as Windows-1252, but ruby won't detect that automatically. You can coax it like this:
my_string = "Sch\xF6ning"
my_string.force_encoding('windows-1252').encode('utf-8')
=> "Schöning"
You can make a reusable converter to help you do the same thing:
ec = Encoding::Converter('windows-1252', 'utf-8')
ec.convert(my_string)
=> "Schöning"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With