From: Robert Klemme Date: 2011-01-14T01:13:38+09:00 Subject: Re: Weird error using String#[] On Thu, Jan 13, 2011 at 4:35 AM, Jason Mcdonald wrote: > Nokogiri is easier... (see below) Certainly! > I would still like to know what exactly is causing the weird behavior in > my original post though, if anyone knows. I can understand why encoding > would result in incorrect parsing, but I don't understand why the > encoding would mess up the hard coded portion of the call to puts still. Can you provide a small program that exhibits the effect you are seeing? It is especially important to see how you calculate indexes. Maybe this can help to illustrate a possible scenario: Ruby version 1.9.2 irb(main):001:0> s = "aä" => "aä" irb(main):002:0> s.encoding => # irb(main):003:0> x = s.dup => "aä" irb(main):004:0> x.encoding => # irb(main):005:0> x.force_encoding "BINARY" => "a\xC3\xA4" irb(main):006:0> x.encoding => # irb(main):007:0> x[1,1] => "\xC3" irb(main):008:0> s[1,1] => "ä" irb(main):009:0> Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/