From: Javier Hidalgo Villegas Date: 2011-05-26T03:35:11+09:00 Subject: Re: String Element Reference --_2d2ac780-fcb5-41fa-9deb-d3555530f50a_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable That is the way String indexing works in Ruby=2C if you only pass one param= eter you'll get the ASCII value of the character. If you would like to get = "h" you must do a[0=2C1] where the first parameter tells the parser to get= the first character of the String and the second parameter tells the numbe= r of characters you want to get from that position. Hope this helps Javier Hidalgo > Date: Thu=2C 26 May 2011 02:23:38 +0900 > From: solomon.jas@gmail.com > Subject: String Element Reference > To: ruby-talk@ruby-lang.org >=20 > I am new to Ruby so I apologize if this seems dumb. >=20 > I am currently running ruby 1.8.7 (2009-06-12 patchlevel 174) > [universal-darwin10.0]. >=20 > When working in an irb session I'm having trouble with String element > reference. >=20 > Example: >=20 > a =3D "hello" >=20 > a[0] should return "h"=2C but instead is returning 104. >=20 > Seems like it's return the ascii value of the element=2C but why? >=20 >=20 > When I do a[0=2C3] the return is the expected "hel". >=20 >=20 >=20 >=20 > Any ideas as to why a[0] is returning a FixNumb object? >=20 > Ideas / help would be greatly appreciated. >=20 > --=20 > Posted via http://www.ruby-forum.com/. >=20 = --_2d2ac780-fcb5-41fa-9deb-d3555530f50a_--