From: Brian Candler Date: 2009-09-02T19:08:49+09:00 Subject: Re: how to convert string to binary and back in Ruby 1.9? I think I understand it now. The following was confusing me initially: >> str = "über" => "über" >> str.force_encoding("ISO-8859-1") => "über" >> str = "groß" => "groß" >> str.force_encoding("ISO-8859-1") => "gro�\x9F" It appears this is just an artefact of String#inspect. String#inspect "knows" that \x80 to \x9F are not printable characters in ISO-8859-1, so converts them to the backslash hex form. This breaks the UTF-8 display by splitting the character, but of course only for strings which contain bytes in that range. You still get the string displayed as UTF-8 using puts without inspect: >> puts str groß => nil It works if you set the encoding for STDOUT inside irb, in which case you'll get everything transcoded to your terminal's character set. >> STDOUT.set_encoding "locale" => #> >> str = "über" => "über" >> str.force_encoding("ISO-8859-1") => "über" >> puts str über => nil >> -- Posted via http://www.ruby-forum.com/.