Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby 2.0 iconv replacement

Tags:

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': cannot load such file -- iconv (LoadError)

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] 

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

like image 919
cnd Avatar asked Apr 16 '13 08:04

cnd


1 Answers

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

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

like image 158
Dane Balia Avatar answered Jan 09 '23 01:01

Dane Balia