"Michael W. Ryder" <_mwryder / worldnet.att.net> writes:

> Was there a reason the string class was implemented with str[i]
> returning the code of position i in str?  The reason I ask this is
> that in other languages str[i] returns the string starting at position
> i. For example C uses t = strcpy(str[i]) and Business Basic uses
> S$=T$(I) to copy a string from position i.

I can't comment on what "Business Basic" uses, but your C code is
completely wrong.  In C, str[i] returns a char which, since C has
"char" as one of its integral types, is equivalent to returning the
character code.

The usual usage of strcpy to copy only from the second (index 1)
character onward is:

   strcpy(dest, src + 1);

(And incidentally, using strcpy instead of strncpy is a practice that
often leads to security vulnerabilities)

In other words, ruby's behavior with str[i] matches the behavior of C
- it returns the character at that position, where "character" is
viewed simply as a number.

-- 
s=%q(  Daniel Martin -- martin / snowplow.org
       puts "s=%q(#{s})",s.map{|i|i}[1]       )
       puts "s=%q(#{s})",s.map{|i|i}[1]