Hi all
I would like to read all the characters in a string. For example
“123456” I need to read every digit separately.
thanks
Hi all
I would like to read all the characters in a string. For example
“123456” I need to read every digit separately.
thanks
On Fri, 05 Sep 2008 12:04:46 +0200, Pepe S. [email protected]
wrote:
I would like to read all the characters in a string. For example
“123456” I need to read every digit separately.
For strings use
“123456”.split(//)
for integers
“123456”.split(//).map{|x| x.to_i}
HTH,
Josef ‘Jupp’ Schugt
2008/9/5 Josef ‘Jupp’ Schugt [email protected]:
On Fri, 05 Sep 2008 12:04:46 +0200, Pepe S. [email protected] wrote:
I would like to read all the characters in a string.
For me, glasses work extremely well.
For example
“123456” I need to read every digit separately.
For strings use
“123456”.split(//)
Or
“12345”.scan /./m do |s|
…
end
Cheers
robert
On Fri, Sep 5, 2008 at 6:04 PM, Pepe S. [email protected] wrote:
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”]
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs