How can I convert a string from windows-1252 to utf-8 in Ruby?

前端 未结 5 2002
日久生厌
日久生厌 2020-12-03 12:04

I\'m migrating some data from MS Access 2003 to MySQL 5.0 using Ruby 1.8.6 on Windows XP (writing a Rake task to do this).

Turns out the Windows string data is encod

5条回答
  •  时光说笑
    2020-12-03 12:45

    If you're on Ruby 1.9...

    string_in_windows_1252 = database.get(...)
    # => "Fåbulous"
    
    string_in_windows_1252.encoding
    # => "windows-1252"
    
    string_in_utf_8 = string_in_windows_1252.encode('UTF-8')
    # => "Fabulous"
    
    string_in_utf_8.encoding
    # => 'UTF-8'
    

提交回复
热议问题