From: Brian Candler Date: 2012-09-21T22:27:43+09:00 Subject: Re: Encoding question Nathan Beyer wrote in post #1076883: >> *No* transcoding takes place in the above example, regardless of the >> where it runs; the data is read into the string as-is. However, every >> String which you read from the file using f.gets or f.getc is marked to >> say that it is encoded using UTF-8. (But not Strings which you read >> using f.read) > > I'm not seeing this behavior. > > 1.9.3-p194 :001 > f = File.open('hello.txt', 'r:windows-1252') > => # > 1.9.3-p194 :002 > c = f.getc > => "h" > 1.9.3-p194 :003 > c.encoding > => # The letter "c" has not been transcoded. It happens to be the same in windows-1252 and UTF-8, the single byte 0x63. However if you try it with a high character >0x80 you'll see that it is not transcoded into UTF-8. Note that a string in ruby 1.9 is a vector of two things: an array of bytes, and an encoding tag claiming that this string is encoded in a particular way. c.encoding only shows you the tag. -- Posted via http://www.ruby-forum.com/.