From: "Thomas T." Date: 2010-12-29T07:58:35+09:00 Subject: convert String "1;2;3;4;5;" to Array [1, 2, 3, 4, 5] I'm trying to convert a String of numbers that are separated by semicolons to an Array---totally for fun, to stretch my ruby understanding, fyi. I use the Array in a while loop which does work when the Array looks like = [1,2,3,4,5,...]---so that part is working. But I want to use ruby to convert a String = "1;2;3;4;5;6;7;8;9;10" into an Array [1,2,3,4,5,...] so that I can use these values. I've tried many a method, but can't seem to get the desired result; I've tried gsub(/\;/, ","), eval (), and others. ########## raw_data = "1;2;3;4;5;6;7;8;9;10" data = raw_data.split(/\;/) #but this gives ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"], not [1, 2, 3,...] #data = [1,2,3,4,5,6,7,8,9,10,11,12] # this is the desired result boundary = 1 ending_boundary = 13 interval = (ending_boundary - boundary)/3 while boundary < ending_boundary print "For the class #{boundary} to #{boundary + interval}, " print "the group is: " puts data.select{ |x| x >= boundary && x < (boundary + interval) }.size print data.select{ |x| x >= boundary && x < (boundary + interval) }.join(' ') boundary = boundary + interval #increase the boundary to the next class print ".\n" end -- Posted via http://www.ruby-forum.com/.