view · edit · sidebar · attach · print · history

<< Array | Index | Beginner >>

Converting ASCII to UTF-8 with Ruby 1.9.3

Run this in Ruby 1.9.3

#encoding: ASCII-8BIT
str = "\xC2\xA92011 AACR"
p str, str.encoding
#=> "\xC2\xA92011 AACR"
#=> #<Encoding:ASCII-8BIT>

str.force_encoding('UTF-8')
p str, str.encoding
#=> "©2011 AACR"
#=> #<Encoding:UTF-8>
view · edit · sidebar · attach · print · history
Page last modified on March 21, 2012, at 02:23 PM