Cant covert array of string in integers

hi all,

i took the desired numbers from the string in datatbase collum
(str=1500,my sql,date 2500,my sql,date)
by str.scan method i got the numbers in a string array(eg=“1500”
“2500”)

now in the controllere method when i do the addition by of this array
elemts by method

hi=str.scan(/^(\d+)/)
num = hi.inject(0){|sum, element|(sum.to_i)+(element.to_i)}

it gives error
‘undefine method to_i’

plssssss help

also can ny1 tell me any other alternative to the abov methode to add
all the elements of the array

Prashant J. wrote:

hi all,

i took the desired numbers from the string in datatbase collum
(str=1500,my sql,date 2500,my sql,date)
by str.scan method i got the numbers in a string array(eg=“1500”
“2500”)

now in the controllere method when i do the addition by of this array
elemts by method

hi=str.scan(/^(\d+)/)
num = hi.inject(0){|sum, element|(sum.to_i)+(element.to_i)}

it gives error
‘undefine method to_i’

plssssss help

also can ny1 tell me any other alternative to the abov methode to add
all the elements of the array

The elements are actually arrays, when I attempt to reconstruct this.

Try this

num = hi.inject(0) { | sum, element| sum + element[0].to_i }

or take a look at hi.inspect

Stephan