使用 Iconv 从 UTF-8 转换为 latin1 时出错
完全的 Ruby 菜鸟,只是想破解一个脚本以使其工作。
irb(main):011:0> Iconv.iconv("LATIN1//IGNORE", "UTF-8", "Résumé")
Iconv::InvalidCharacter: "\351"
from (irb):11:in `iconv'
from (irb):11
from :0
irb(main):012:0> Iconv.iconv("LATIN1//TRANSLIT//IGNORE", "UTF-8", "Résumé")
Iconv::IllegalSequence: "\351sum\351"
from (irb):12:in `iconv'
from (irb):12
from :0
irb(main):002:0> "Résumé".encoding
NoMethodError: undefined method `encoding' for "R\351sum\351":String
from (irb):2
Total Ruby noob, just trying to hack a script to make it work.
irb(main):011:0> Iconv.iconv("LATIN1//IGNORE", "UTF-8", "Résumé")
Iconv::InvalidCharacter: "\351"
from (irb):11:in `iconv'
from (irb):11
from :0
irb(main):012:0> Iconv.iconv("LATIN1//TRANSLIT//IGNORE", "UTF-8", "Résumé")
Iconv::IllegalSequence: "\351sum\351"
from (irb):12:in `iconv'
from (irb):12
from :0
irb(main):002:0> "Résumé".encoding
NoMethodError: undefined method `encoding' for "R\351sum\351":String
from (irb):2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于它已经将您的输入字符串解释为 LATIN1,因此您无法沿着该路径转换它。您可能需要将编码设置为 UTF-8 才能启动。
\351
是 LATIN1é
字符。您想要以下结果:
您可以检查您的
LANG
环境变量,或者您的平台用于确定默认字符编码的任何变量。Since it's interpreting your input string as LATIN1 already, you can't convert it along that path. You may need to set your encoding to be UTF-8 to start.
\351
is a LATIN1é
character.You want the following result:
You could check your
LANG
environment variable, or whatever your platform uses to determine the default character encoding.