[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

STRING FUNCTIONS

Newb Newb

8/21/2008 8:44:00 AM

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

3 Answers

WujcioL

8/21/2008 8:49:00 AM

0

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

Stefano Crocco

8/21/2008 8:51:00 AM

0

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

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


Jan Pilz

8/21/2008 9:06:00 AM

0

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 http://www.ruby-doc... 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