--_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, if you only pass one parameter you'll get the ASCII value of the character. If you would like to get "h" you must do  a[0,1] where the first parameter tells the parser to gethe first character of the String and the second parameter tells the number of characters you want to get from that position.
Hope this helps
Javier Hidalgo




> Date: Thu, 26 May 2011 02:23:38 +0900
> From: solomon.jas / gmail.com
> Subject: String Element Reference
> To: ruby-talk / ruby-lang.org
> 
> I am new to Ruby so I apologize if this seems dumb.
> 
> I am currently running ruby 1.8.7 (2009-06-12 patchlevel 174)
> [universal-darwin10.0].
> 
> When working in an irb session I'm having trouble with String element
> reference.
> 
> Example:
> 
> a = "hello"
> 
> a[0] should return "h", but instead is returning 104.
> 
> Seems like it's return the ascii value of the element, but why?
> 
> 
> When I do a[0,3] the return is the expected "hel".
> 
> 
> 
> 
> Any ideas as to why a[0] is returning a FixNumb object?
> 
> Ideas / help would be greatly appreciated.
> 
> -- 
> Posted via http://www.ruby-forum.com/.
> 
 		 	   		  -_2d2ac780-fcb5-41fa-9deb-d3555530f50a_--