Force UTF-8 encoding

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

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

I will not always know the encoding supplied, and this is the result of
some_string.encode("UTF-8")

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.

Hi,

In order to solve this issue, I use the chardet gem
https://rubygems.org/gems/chardet to identify the file encoding and then
I
iconv it to utf-8.

Mickael

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