About the author

Love interactivity, programming, music and the web.

Currently work using Ruby/Rails, JavaScript and ActionScript, but know other languages.

Developer at Ocapi

Find me on

Ensure UTF-8 string from any source with Ruby

August 1st 2011

Sometimes, when you need to download an html web page, it can be interpreted as a wrong encoding, causing errors with accents, and special characters.

You can avoid those problems converting to UTF-8. As follows:

And just calling ensure_utf8 function:

Hope it helps.

Tags: ruby encoding ensure utf8