STRING FUNCTIONS

N

Newb Newb

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..
 
M

Mateusz Tybura

Newb said:
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
 
S

Stefano Crocco

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..

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
 
J

Jan Pilz

Newb said:
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 http://www.ruby-doc.org/core/ to your Favorites, look at
Class "String" and you will find everything you need.

--
Otto Software Partner GmbH

Jan Pilz (e-mail: (e-mail address removed))

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,052
Members
47,656
Latest member
rickwatson

Latest Threads

Top