如何将 utf8 字符转换为 iso8859-1 [英] How can i transform the utf8 chars to iso8859-1

查看:86
本文介绍了如何将 utf8 字符转换为 iso8859-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是标题说的!谁能告诉我如何在 ruby​​ 中做到这一点!

the question is that the title say! who can tell me how do this in ruby!

推荐答案

~ UPDATE ~

ruby-iconv 从 Ruby 1.9.3 开始被 encode 方法.请参阅Jörg W Mittag 的回答 了解详情,但简而言之:

~ UPDATE ~

ruby-iconv has been superseded from Ruby 1.9.3 onwards by the encode method. See Jörg W Mittag's answer for details, but in short:

utf8string = "èàòppè"
iso_string = utf8string.encode('ISO-8859-1')

<小时>

我同意 Williham Totlandt 的观点,即这种类型的转换可能不是有史以来最聪明的想法,但无论如何:使用 ruby-iconv :)

utf8string = "èàòppè"
iso_string = Iconv.conv 'iso8859-1', 'UTF-8', utf8string 

这篇关于如何将 utf8 字符转换为 iso8859-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆