![](/img/trans.png)
[英]How can I convert a string from windows-1252 to utf-8 in Ruby?
[英]How can I convert character references to UTF-8 strings in Ruby?
我有一些來自Feed的內容。 在這些提要中,UTF-8字符通常被編碼為字符引用,即“å”是“å”。 為了避免在我的視圖中對它們進行雙重編碼(即“å”),我想將它們轉換回正常的UTF_8字符。 我怎么能用Ruby做到這一點?
我想要:
“å”。convert_to_utf8 =>“å”
HTMLEntities gem旨在實現這一目標。
require 'htmlentities'
coder = HTMLEntities.new
string = "élan"
coder.decode(string) # => "élan"
# or
string.decode_entities # => "élan"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.