I have string.
In that i need to display the first element from String means Which
Function Should I use?
I Am Unable To Figure Out..
···
--
Posted via http://www.ruby-forum.com/.
I have string.
In that i need to display the first element from String means Which
Function Should I use?
I Am Unable To Figure Out..
--
Posted via http://www.ruby-forum.com/.
Newb Newb wrote:
I have string.
In that i need to display the first element from String means Which
Function Should I use?
I Am Unable To Figure Out..
If you mean first letter :
name[0] #shows code
name[0].chr #shows letter
--
Posted via http://www.ruby-forum.com/\.
Try String# or String#slice, but since they return a number (the code of the
first character) if you only specify an index, you'll need to pass the index
and a length of 1, like this:
"test string"[0,1]
=> "t"
For more information, see the documentation for the String#slice method (ri
String#slice).
Stefano
On Thursday 21 August 2008, Newb Newb wrote:
I have string.
In that i need to display the first element from String means Which
Function Should I use?
I Am Unable To Figure Out..
Newb Newb schrieb:
I have string.
In that i need to display the first element from String means Which
Function Should I use?
I Am Unable To Figure Out..
"ASDASDAS"[0] -> 65
"ASDASDAS"[0].chr -> "A"
Please add RDoc Documentation to your Favorites, look at Class "String" and you will find everything you need.
--
Otto Software Partner GmbH
Jan Pilz (e-mail: Jan.Pilz@osp-dd.de)
Tel. 0351/49723202, Fax: 0351/49723119
01067 Dresden, Freiberger Straße 35 - AG Dresden, HRB 2475
Geschäftsführer: Burkhard Arrenberg, Heinz A. Bade, Jens Gruhl