[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: string#[]

Frank Davis

9/26/2006 4:33:00 PM

I think Ruby treats Strings as an array of bytes. There are a lot of
benefits to it. Ruby is built on top of (and is extensible with) C, in
which strings really are an array of bytes. String supports the Pack and
Unpack operations, which allows you to use the String class when dealing
with all kinds of binary data, including making calls to external
libraries (.so files, .dll files, etc.). It's a little funky, but it
seems to work well.

-----Original Message-----
From: Newbie [mailto:none@none.com]
Sent: Tuesday, September 26, 2006 9:15 AM
To: ruby-talk ML
Subject: Re: string#[]


Why not a 1-character string?

Robert Klemme wrote:
>> This must be a common newbie question, but I can't find the answer.
>>
>> Why does string#[] return an ASCII code, rather than a character?
>>
>> "abc"[1,2] #-> "bc"
>> "abc"[1..2] #-> "bc"
>> "abc"[1] #-> 98
>
> Because there is no character class in Ruby.
> <snip>