 
 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) | ||
|---|---|---|
| Code | Expected | Actual | 
| doc = %{<?xml version="1.0"?>
     <menu tipo="specialitą" giorno="venerdģ">
    <primo_piatto>spaghetti al ragł</primo_piatto>
       <bevanda>frappč</bevanda>
     </menu>}
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 = Iconv.new(output_encoding, input_encoding).iconv(doc) CharGuess::guess(converted_doc) | "UTF-8" | "UTF-8" |