Ruby 2.0 iconv 替换 [英] Ruby 2.0 iconv replacement

查看:48
本文介绍了Ruby 2.0 iconv 替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不会 Ruby 但想在以下位置运行脚本:

I don't know Ruby but want to run an script where:

D:/Heather/Ruby/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': 无法加载此类文件 -- iconv (LoadError)

D:/Heather/Ruby/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- iconv (LoadError)

如果我注释 iconv 代码它会以某种方式工作,但如果我可以重新编码这部分会更好:

it works somehow if I comment iconv code but it will be much better if I can recode this part:

return Iconv.iconv('UTF-8//IGNORE', 'UTF-8', (s + ' ') ).first[0..-2]

没有iconv.也许我可以在这里以某种方式使用 String#encode ?

without iconv. Maybe I can use String#encode here somehow?

推荐答案

Iconv 在 1.9.3 中被弃用(移除).您仍然可以安装它.

Iconv was deprecated (removed) in 1.9.3. You can still install it.

如果您不确定,请参考资料:https://rvm.io/packages/iconv/

Reference Material if you unsure: https://rvm.io/packages/iconv/

但是建议您不要使用,而是使用:

However the suggestion is that you don't and rather use:

string.encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "?")

API

这篇关于Ruby 2.0 iconv 替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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