Topic: handling non standard characters

Here's a strange one:  When writing a string to a mysql database, this innocent looking hyphen in "kanga

Zubin

Re: handling non standard characters

Try the Iconv gem.  Install it with "gem install iconv" and use it like so:

a = "kanga­-roos"
sane_a = Iconv.iconv('ascii//ignore//translit', 'utf-8', a)
puts sane_a # => "kangaroos"

Re: handling non standard characters

Thank you once again Danger, that worked perfectly!

I wasn't install the gem though:

$ sudo gem install iconv
ERROR:  While executing gem ... (Gem::GemNotFoundException)
    Could not find iconv (> 0) in any repository

Fortunately it appears to be preinstalled on OSX, and it just worked:

$ irb
irb(main):001:0> require "iconv"
=> true
irb(main):002:0> a="kanga

Zubin

Re: handling non standard characters

Actually, some other unexpected characters were still appearing using Iconv.iconv

I found this worked for me (odd because it seems like the equivalent):

Iconv.new('ascii//ignore//translit', 'utf-8').iconv(str)

Zubin