[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: string slice elegant way

Peña, Botp

3/4/2006 12:41:00 AM

Mage [mailto:mage@mage.hu]

#a = 'hello there'
#and I need 'llo there'
#
#a[2,a.size] works, but I find it ugly because the given length
#is larger
#than the real length of the result.
#a[2,a.size - 2] is okay, but it is not DRY.
#
#Is there any elegant way, like a[2:] in Python?

is a[2..-1] good enough?



1 Answer

Pete

3/4/2006 5:41:00 AM

0

this is the closest I could think of:

a = "hello there"
a[-9,9]
> llo there

> --- Ursprüngliche Nachricht ---
> Von: "Pena, Botp" <botp@delmonte-phil.com>
> An: ruby-talk@ruby-lang.org (ruby-talk ML)
> Betreff: Re: string slice elegant way
> Datum: Sat, 4 Mar 2006 09:41:13 +0900
>
> Mage [mailto:mage@mage.hu]
>
> #a = 'hello there'
> #and I need 'llo there'
> #
> #a[2,a.size] works, but I find it ugly because the given length
> #is larger
> #than the real length of the result.
> #a[2,a.size - 2] is okay, but it is not DRY.
> #
> #Is there any elegant way, like a[2:] in Python?
>
> is a[2..-1] good enough?
>
>