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-...
.
>
>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Getting last character from a string
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password