Getting certain characters from a string

I have a string that I need to get certain characters at a given index.
However, doing something like str[0] gives the ascii number, not the
actual
character. How do I get it to give me the character?

Reese C. wrote in post #1030886:

I have a string that I need to get certain characters at a given index.
However, doing something like str[0] gives the ascii number, not the
actual
character. How do I get it to give me the character?

str[0,1]

This is compatible with both ruby 1.8 and ruby 1.9.

I believe you’re looking for the chr method

As in

string[0].chr

I love this mailing list. I’m learning new things every day. Thank you
Reese.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs