# Re: string slice elegant way

**URL:** <https://www.ruby-forum.com/t/re-string-slice-elegant-way/76494>\
**Category:** Ruby\
**Created:** [March 4, 2006, 1:41am UTC](https://www.ruby-forum.com/t/re-string-slice-elegant-way/76494 "2006-03-04T01:41:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PenaS\_Botp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@PenaS\_Botp](https://www.ruby-forum.com/u/PenaS_Botp)\
**Post date:** [March 4, 2006, 1:41am UTC](https://www.ruby-forum.com/t/re-string-slice-elegant-way/76494/1 "2006-03-04T01:41:37Z")

</div>

Mage [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

#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?

---

<div class="post-metadata">

**Author:** ![PenaS\_Botp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@PenaS\_Botp](https://www.ruby-forum.com/u/PenaS_Botp)\
**Post date:** [March 4, 2006, 6:43am UTC](https://www.ruby-forum.com/t/re-string-slice-elegant-way/76494/2 "2006-03-04T06:43:23Z")

</div>

this is the closest I could think of:

a = “hello there”  
a[-9,9]

> llo there
