On Thursday 24 September 2009, ThomasW wrote: > |Hi all, > | > |I read from to the docs[1] that string[index] should do the > |following: "If passed a single Fixnum, returns the code of the > |character at that position." > | > |This is working as documented with Ruby 1.8.6, but it isn't with Ruby > |1.9.1p129 (on my WinXP machine). Why is this so? > | > |Thanks for any hints > |Thomas W. > | > |[1] http://ruby-doc.org/core/classes/String.html#M000771 > | Because you're looking at the documentation for ruby 1.8, not at that for ruby 1.9. The documentation for ruby 1.9, which you can find at http://ruby-doc.org/ruby-1.9/index.html, states that in ruby 1.9, String#[] returns the character at the given position, not its code. To obtain the code of the character, you can use its ord method: 'a'.ord => 97 I hope this helps Stefano