Accessing each character of a string

I think the issue arises because, in Ruby, a String object is
used to hold human-readable code-points in a character set as
well as variable-length binary data. If you want the 3rd byte
of a protocol header then p[2] returning a numeric value makes
a lot of sense instead of "k" (for example).

The entire issue of fonts, character-sets, internationalization,
and such is pretty complicated. Fitting all that as well as
basic binary-data access into a single interface called String
is probably overloading things a bit much and I think that is
the motivation for doing things differently in Rite (Ruby 2.0).

Gary Wright

···

On May 19, 2005, at 4:25 AM, Lawrence Oluyede wrote:

Yeah I think it's the better workaround, using range to extract
a single char seems very odd to me. Anyway I prefer the Python
"style" where "hello"[0] returns the char and you can always
use ord() function to get the number. How many people iterate
trough strings to get the ordinal numbers?

Thanks for the explanation :slight_smile:

···

Il 2005-05-19, gwtmp01@mac.com <gwtmp01@mac.com> ha scritto:

The entire issue of fonts, character-sets, internationalization,
and such is pretty complicated. Fitting all that as well as
basic binary-data access into a single interface called String
is probably overloading things a bit much and I think that is
the motivation for doing things differently in Rite (Ruby 2.0).

--
Lawrence
http://www.oluyede.org/blog