If I something like word = "ruby"
can't I do something like (I thought it was possible)
word[0] -> r
word[1] -> u
word[2] -> b
word[3] -> y
Trying something like that now and it's giving me "weird" numbers
Yet I'm trying it (both program and irb) and it gives me weird numbers
irb(main):010:0> word = "ruby"
=> "ruby"
irb(main):011:0> puts word[0]
114
=> nil
irb(main):012:0> puts word[2]
98
=> nil
irb(main):013:0> puts word[3]
121
=> nil
So what am I doing wrong ?
TIA
Stuart
Dark Ambient wrote:
If I something like word = "ruby"
can't I do something like (I thought it was possible)
word[0] -> r
word[1] -> u
word[2] -> b
word[3] -> y
Trying something like that now and it's giving me "weird" numbers
Yet I'm trying it (both program and irb) and it gives me weird numbers
irb(main):010:0> word = "ruby"
=> "ruby"
irb(main):011:0> puts word[0]
114
=> nil
irb(main):012:0> puts word[2]
98
=> nil
irb(main):013:0> puts word[3]
121
=> nil
So what am I doing wrong ?
TIA
Stuart
We _just_ discussed this:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/200453
Also check the documentation.
http://ruby-doc.org/core/classes/String.html#M001843
-Justin
-Justin
Or even on your own machine:
$ ri String#
... ri output
···
On Jul 6, 2006, at 5:01 PM, Justin Collins wrote:
Dark Ambient wrote:
If I something like word = "ruby"
can't I do something like (I thought it was possible)
word[0] -> r
word[1] -> u
word[2] -> b
word[3] -> y
Trying something like that now and it's giving me "weird" numbers
Yet I'm trying it (both program and irb) and it gives me weird numbers
irb(main):010:0> word = "ruby"
=> "ruby"
irb(main):011:0> puts word[0]
114
Also check the documentation.
class String - RDoc Documentation
--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant
http://trackmap.robotcoop.com
Ahh...so those numbers are the character codes ?
Stuart
···
On 7/6/06, Eric Hodel <drbrain@segment7.net> wrote:
On Jul 6, 2006, at 5:01 PM, Justin Collins wrote:
> Dark Ambient wrote:
>> If I something like word = "ruby"
>> can't I do something like (I thought it was possible)
>>
>> word[0] -> r
>> word[1] -> u
>> word[2] -> b
>> word[3] -> y
>>
>> Trying something like that now and it's giving me "weird" numbers
>>
>> Yet I'm trying it (both program and irb) and it gives me weird
>> numbers
>>
>> irb(main):010:0> word = "ruby"
>> => "ruby"
>> irb(main):011:0> puts word[0]
>> 114
>
> Also check the documentation.
> class String - RDoc Documentation
Or even on your own machine:
$ ri String#
... ri output
--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant
http://trackmap.robotcoop.com
$ ri String#
[...]
Element Reference---If passed a single +Fixnum+, returns the code
of the character at that position. If passed two +Fixnum+ objects,
[...]
See also Integer#chr.
···
On Jul 6, 2006, at 5:17 PM, Dark Ambient wrote:
On 7/6/06, Eric Hodel <drbrain@segment7.net> wrote:
On Jul 6, 2006, at 5:01 PM, Justin Collins wrote:
> Also check the documentation.
> class String - RDoc Documentation
Or even on your own machine:
$ ri String#
... ri output
Ahh...so those numbers are the character codes ?
--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant
http://trackmap.robotcoop.com