# Difference between \[0..0\] and \[0\]

**URL:** <https://www.ruby-forum.com/t/difference-between-0-0-and-0/120439>\
**Category:** Rails\
**Created:** [November 16, 2007, 11:01pm UTC](https://www.ruby-forum.com/t/difference-between-0-0-and-0/120439 "2007-11-16T23:01:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [November 16, 2007, 11:01pm UTC](https://www.ruby-forum.com/t/difference-between-0-0-and-0/120439/1 "2007-11-16T23:01:59Z")

</div>

I am trying to get at the first character in a string and when I say  
@string[0] I get an integer value, but when I say @string[0…0] I get  
the character. Why is that? Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [November 16, 2007, 11:23pm UTC](https://www.ruby-forum.com/t/difference-between-0-0-and-0/120439/2 "2007-11-16T23:23:05Z")

</div>

Strings are not treated the same as arrays. A single number in the  
brackets gives you the ASCII value of the character at that position.  
If you want the first character, I’d use @string[0,1] which gives you  
a substring starting at the 0th position, with a length of 1.

* * *

Chris

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [November 17, 2007, 12:03am UTC](https://www.ruby-forum.com/t/difference-between-0-0-and-0/120439/3 "2007-11-17T00:03:28Z")

</div>

On Nov 16, 2007, at 5:22 PM, Chris E. wrote:

> > I am trying to get at the first character in a string and when I say  
> > @string[0] I get an integer value, but when I say @string[0…0] I get  
> > the character. Why is that? Thanks,
> > 
> > -S

BUT, this will change in Ruby 2.0 so that “abc”[0] will be “a” rather  
than 97

It seems to be true that “something”[n] is the same value as  
“something”[n…n][0] for all n

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
