getting character(s) of a string at specified positions.

M

Matt Roth

------=_Part_1441_6141412.1133114401215
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Ok, so lets say I have this:

myString =3D gets

I wanted to find what character is at position 5.

so if the use inputs

"How much wood would a wood-chuck chuck if a wood-chuck could chuck wood"

I would find that the character there is "m".

How would I find the fifth character?

------=_Part_1441_6141412.1133114401215--
 
M

Michal

Hi,
"How much wood would a wood-chuck chuck if a wood-chuck could chuck wood"

I would find that the character there is "m".

How would I find the fifth character?

irb(main):001:0> a="How much wood would a wood-chuck chuck if a wood-chuck could chuck wood"
=> "How much wood would a wood-chuck chuck if a wood-chuck could chuck wood"
irb(main):002:0> a[4,1]
=> "m"

M.
 
A

Alex Fenton

Matt said:
"How much wood would a wood-chuck chuck if a wood-chuck could chuck wood"

I would find that the character there is "m".

How would I find the fifth character?

myString[4].chr

or

myString[4, 1]
 
A

Austin Ziegler

Matt said:
"How much wood would a wood-chuck chuck if a wood-chuck could chuck woo= d"

I would find that the character there is "m".

How would I find the fifth character?

myString[4].chr

or

myString[4, 1]

or

myString[4..4]

or

myString[4...5]

-austin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top