I'm working on a ruby script (using sequel) to transfer data from an old database to a new one. Because of an encoding problem with the old database I got values like "München" instead of "München".
DB = Sequel.mysql2 'db_name', user: 'name', password: '***', host: '127.0.0.1' # , encoding: Encoding::CP1252.name) # doesn't work
city = DB[:users].first['city'] # => "München"
city.encoding # => #<Encoding:UTF-8>
city.encode(Encoding::UTF_8, Encoding::CP1252) # => "München"
The old db's encoding is set to CP1252, the new one is utf-8.
I tried to #gsub the broken umlauts, but that doesn't work:
umlauts = {
'ä' => 'ä',
'ö' => 'ö',
'ü' => 'ü',
'ß' => 'ß'
}
city.gsub(/[#{umlauts.keys.join}]/, umlauts) # => "Mnchen"
I'm completely clueless how to correctly work with encoding, do you know how I can get 'München'?
string = "München";string.gsub("ü", "ü");=> "München"