This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.

Converting From One Encoding to Another (written by Mauro Cicio)
doc = %{<?xml version="1.0"?>
     <menu tipo="specialitą" giorno="venerdģ">
    <primo_piatto>spaghetti al ragł</primo_piatto>
require 'iconv'
require 'charguess' # not necessary if input encoding is known
input_encoding = CharGuess::guess doc
"windows-1252" "windows-1252"
output_encoding = 'utf-8'
converted_doc =, input_encoding).iconv(doc)
"UTF-8" "UTF-8"