Hello!
I have a very small question.
How can I convert these:
[172592596,93038592,154137572]
To look like these:
['172592596','93038592','154137572']
Thankful for all help!
Hello!
I have a very small question.
How can I convert these:
[172592596,93038592,154137572]
To look like these:
['172592596','93038592','154137572']
Thankful for all help!
Try this!
b = []
a = [172592596,93038592,154137572]
a.each {|a1| b << a1.to_s}
b will return ["172592596", "93038592", "154137572"]
You can also use collect! same as map like @sepp2k suggested.
a = [172592596,93038592,154137572]
a.collect! {|x| x.to_s}
If you want to turn an array of ints into an array of strings, you can do so easily using map
and to_s
.
arr = [172592596,93038592,154137572]
arr.map {|x| x.to_s}
#=> ["172592596", "93038592", "154137572"]
Since this is rails, you can also do (will also work in plain ruby if the version is at least 1.8.7):
arr.map(&:to_s)
To get the same result.