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.
我想我对这里发生的事情有一个模糊的概念,但我无法做出正确的解释。不过,这是一种至少适用于您的一个示例的解决方案:
str = "ãƒ\u008F" str2 = str.chars.map {|c| c.encode('windows-1252').ord rescue c.ord } .pack('C*').force_encoding('utf-8') puts str2 # => ハ
当然,这对于大文本来说效率很低,但希望它会有所帮助。如果稍后我有足够的资金,我会回来尝试添加更好的解释。