Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串,例如:
"MÃ\u0083¼LLER".encoding #<Encoding:UTF-8> "MÃ\u0083¼LLER".inspect "\"MÃ\\u0083¼LLER\""
我能做些什么来挽救这样的字符串?考虑到我没有原始数据。这是可以挽救的吗?
看起来字符串从 utf-8 转换为 latin-1两次。在您的一些数据上试试这个,如果它有效,请告诉我:
require 'iconv' def decode(str) i = Iconv.new('LATIN1','UTF-8') i.iconv(i.iconv(str)).force_encoding('UTF-8') end decode("MÃ\u0083¼LLER") #=> "MüLLER"