How to read digits in a number

Hi all

I would like to read all the characters in a string. For example
"123456" I need to read every digit separately.

thanks

···

--
Posted via http://www.ruby-forum.com/.

For strings use

"123456".split(//)

for integers

"123456".split(//).map{|x| x.to_i}

HTH,

Josef 'Jupp' Schugt

···

On Fri, 05 Sep 2008 12:04:46 +0200, Pepe Sanchez <jsnit@jsnit.com> wrote:

I would like to read all the characters in a string. For example
"123456" I need to read every digit separately.

--
Blog: http://penpen.goodaddress.eu/
PGP key (id 6CC6574F): http://wwwkeys.de.pgp.net/
Jabber - http://www.jabber.org/ - contact information on request

I would like to read all the characters in a string. For example
"123456" I need to read every digit separately.

"1234".each_char{|x| p x}

"1"
"2"
"3"
"4"
=> "1234"

"1234".each_char.map

=> ["1", "2", "3", "4"]

···

On Fri, Sep 5, 2008 at 6:04 PM, Pepe Sanchez <jsnit@jsnit.com> wrote:

I would like to read all the characters in a string.

For me, glasses work extremely well. :wink:

For example

"123456" I need to read every digit separately.

For strings use

"123456".split(//)

Or

"12345".scan /./m do |s|
...
end

Cheers

robert

···

2008/9/5 Josef 'Jupp' Schugt <jupp@gmx.de>:

On Fri, 05 Sep 2008 12:04:46 +0200, Pepe Sanchez <jsnit@jsnit.com> wrote:

--
use.inject do |as, often| as.you_can - without end