[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: accessing each character of a string

Gary Wright

5/19/2005 6:21:00 PM

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?
>

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



1 Answer

Lawrence Oluyede

5/19/2005 6:42:00 PM

0

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).

Thanks for the explanation :)


--
Lawrence
http://www.oluyed...