From: Davi Barbosa Date: 2008-11-04T04:04:23+09:00 Subject: Re: Iconv and incompatible encodings Hello, I was going crazy with this problem. I searched a lot and found some people with the same problem: Iconv works with irb but not in a ruby script. The solution was take another way. For example, Daniel Lucraft (http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/306663) made 3 suggestions. The first one is use Ruby-GNOME2 library and: require 'gtk2' ascii = GLib.convert(string, "ASCII//translit", "UTF-8") This not only worked for me, as the Iconv started to work as expected! For instance: require 'iconv' require 'gtk2' puts Iconv.conv("ASCII//translit","UTF-8","áàâä") gives 'aaaa'. The second solution: ascii = %x{echo "#{str}" | iconv -f "ISO-8859-1" -t "US-ASCII//TRANSLIT"} also worked here. The problem is that I'm not using a ruby script, I'm making an web page with mod_ruby. So, %x{} gives an 'Insecure operation' error and "require 'gtk2'" gives: /var/www/dev/q/test.rbx:12: Cannot open display: /usr/lib/ruby/1.8/gtk2.rb:12 ./lib.rb:31:in `require' His last suggestion is to write your own wrapper. Of course I've not tried. Finally, I used the hack: Unicode.normalize_KD(string).gsub(/[^\x00-\x7F]/n,'') as described here: http://www.ruby-forum.com/topic/70827, and this looks to work fine to remove accents (but I'm not sure if the result is an ascii string) -- Posted via http://www.ruby-forum.com/.