From: Lui Kore Date: 2010-01-18T13:23:14+09:00 Subject: Re: Strange Encoding Behavior I know String#encode doesn't change the original string, but the result is encoded. To understand the problem, you should try in a gbk/shift-jis environment with some Chinese or Japanese path. The point is: For some path p1 and p2, when p1 == p2 and p1.encoding == p2.encoding, p1.encode('utf-8') == p2.encode('utf-8') is not always true. To describe it in a "encode!" version: For some path p1 and p2, when p1 == p2 and p1.encoding == p2.encoding, p1.encode!('utf-8') p2.encode!('utf-8') p1 == p2 is still not always true Robert Klemme wrote: > On 01/17/2010 04:55 AM, Lui Kore wrote: >> #=> "1.9.1 i386-mingw32" is my ruby version >> # changed at last > I believe the point you are missing is that String#encode does not > change the String but it returns a new String with the desired encoding. > If you want inplace modification you need to use String#encode! which > does just that. > > irb(main):006:0> s="foo" > => "foo" > irb(main):007:0> s.encoding > => # > irb(main):008:0> x = s.encode "ASCII" > => "foo" > irb(main):009:0> s.encoding > => # > irb(main):010:0> x.encoding > => # > irb(main):011:0> > > > Kind regards > > robert -- Posted via http://www.ruby-forum.com/.