[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Getting last character from a string

Gennady Bystritsky

2/12/2006 5:27:00 AM

x[-1].chr

[tiger-ppc.gfbm:246]bystr> irb
irb(main):001:0> s = "abc"
=> "abc"
irb(main):002:0> s[-1]
=> 99
irb(main):003:0> s[-1].chr
=> "c"

irb(main):004:0>

> -----Original Message-----
> From: list-bounce@example.com
> [mailto:list-bounce@example.com] On Behalf Of draco draco
> Sent: Saturday, February 11, 2006 16:08
> To: ruby-talk ML
> Subject: Getting last character from a string
>
> Hello
> I'm new to Ruby. I've a simple question.
> Is there a more readable way to get last character from
> string than this one? :
>
> x = "text"
> last_char = x[x.length-1, x.length-1]
>
> --
> Posted via http://www.ruby-....
>
>