From: Robert Dober Date: 2008-05-26T20:21:31+09:00 Subject: Re: Why "ABCDE"[0] returns an integer instead of 'A' ? On Mon, May 26, 2008 at 12:27 PM, Iņaki Baz Castillo wrote: > Hi, I cannot understand how a high level language as Ruby doesn't > handle a simple thing as C does with strings: > > in C: > string = "ABCDE" > string[0] > => 'A' > > in Ruby: > string = "ABCDE" > string[0] > => 65 Maybe because a) in C 'A' == 65 b) Ruby has different ways to get substrings, x[0,1] or x[0..0] c) Matz thought it was a good idea ;) d) it makes lots of sense, unknown paradigms are not necessarily worse than know ones. However, IIRC Ruby1.9 will as you have said below tell the contrary :( > > Why 65? it's the Ascii value of A: > puts "\x65" > => "e" because of "e"[0] == ?e && ?e == 0x65, what did you want to do with \x? > > PD: I've realized when writting this mail that Ruby 1.9 already > implement this "feature". Yup, obviously too many people were puzzled by this. > > -- > Iņaki Baz Castillo > > HTH Robert -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein