# How get a substring of a string

**URL:** <https://www.ruby-forum.com/t/how-get-a-substring-of-a-string/98014>\
**Category:** Rails\
**Created:** [July 11, 2006, 11:54pm UTC](https://www.ruby-forum.com/t/how-get-a-substring-of-a-string/98014 "2006-07-11T23:54:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sail](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5fc32e/32.png) [@sail](https://www.ruby-forum.com/u/sail)\
**Post date:** [July 11, 2006, 11:54pm UTC](https://www.ruby-forum.com/t/how-get-a-substring-of-a-string/98014/1 "2006-07-11T23:54:16Z")

</div>

hello all

i want to get the substring of a string

i found a source that do it…but don’t work in my machine

example

“the source of ruby”.chars[0…5]

that must return “the so”

---

<div class="post-metadata">

**Author:** ![sail](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5fc32e/32.png) [@sail](https://www.ruby-forum.com/u/sail)\
**Post date:** [July 12, 2006, 12:16am UTC](https://www.ruby-forum.com/t/how-get-a-substring-of-a-string/98014/2 "2006-07-12T00:16:41Z")

</div>

Just use the syntax…without “chars”

e.g.  
a=“the source of ruby”  
a[0…5] =\> “the so”

## \_Hari

View this message in context:  
[http://www.nabble.com/how-get-a-substring-of-a-string-tf1927484.html#a5279004](http://www.nabble.com/how-get-a-substring-of-a-string-tf1927484.html#a5279004)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![sail](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5fc32e/32.png) [@sail](https://www.ruby-forum.com/u/sail)\
**Post date:** [July 12, 2006, 12:44am UTC](https://www.ruby-forum.com/t/how-get-a-substring-of-a-string/98014/3 "2006-07-12T00:44:51Z")

</div>

tanks

Nara H.

it work very well

i need it to resolve the number of day in the week…  
i’ll get it from the string that return the function Date.today  
i’l take the three first characters to identify the day

🙂

tankes

---

<div class="post-metadata">

**Author:** ![sail](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5fc32e/32.png) [@sail](https://www.ruby-forum.com/u/sail)\
**Post date:** [July 12, 2006, 12:27pm UTC](https://www.ruby-forum.com/t/how-get-a-substring-of-a-string/98014/4 "2006-07-12T12:27:46Z")

</div>

Or you can use strftime. That is Time.now.strftime(“%b”)

look at [strftime](http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html)  
for other usages of strftime.

---

<div class="post-metadata">

**Author:** ![sail](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5fc32e/32.png) [@sail](https://www.ruby-forum.com/u/sail)\
**Post date:** [July 12, 2006, 12:03pm UTC](https://www.ruby-forum.com/t/how-get-a-substring-of-a-string/98014/5 "2006-07-12T12:03:05Z")

</div>

sail wrote on 12.07.2006 00:44:

> i’l take the three first characters to identify the day  
> Mmh?  
> You use Date. Why you don’t use Date.today.wday?
