Force UTF-8 encoding

I’m writing an upload script for contact management, but having encoding

#=> Encoding::UndefinedConversionError: “\xFA” from ASCII-8BIT to UTF-8

I will not always know the encoding supplied, and this is the result of

I have also tried .force_encoding(“UTF-8”) to no avail. For now I’m
simply trying to bypass invalid characters by replacing them with ? or
removing them completely so Postgres doesn’t blow up on insert.

Any help or advice would be appreciated,
Garrett L.


In order to solve this issue, I use the chardet gem to identify the file encoding and then
iconv it to utf-8.


On 23 January 2011 22:21, Garrett L.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs