From: Morton Goldberg Date: 2007-07-28T01:55:07+09:00 Subject: Re: How to delete array element and add to previous element On Jul 27, 2007, at 2:12 AM, Al Cholic wrote: > Only the third column with the R37,R39,R41,R42,R43,R49 can spill > over to > the next line. Yes, the elements are separated by tabs like you said. > I have managed to get the lines into an array by just using > inputed_text.strip.split("\n") > So now I have an array that contains each line as its elements. > But the > problem is that I need to get the spilled over lines into a > subarray of > the right line. I think this is the easiest way to organize the data. > After i get the spilled over elements to the right location i can go a > head and put the data into a database because I know which element in > the array represents what. I hope this helped in clarifying the > issue. The following code isn't a full solution to your problem, but I think it might suggest a strategy you can use. raw_data = DATA.read data = [] raw_data.each do |line| data << line.chomp.split(/\t/) end primary = nil data.each_with_index do |row, i| if row[0].empty? primary[2] << row[2] data[i] = nil else primary = row end end data.compact! p data __END__ 49 7 RP13,RP15,RP17,RP19,RP24, 12X2 33XD Wireless, Independent, 5% RP32,RP33 50 4 RP27,RP28,RP30,RP31 10XC4 3X567 Network, Isolated, 5% 51 31 R1,R2,R8,R30,R32,R33,R35, 0603,R10K,1% 0603 3%,1/12W R37,R39,R41,R42,R43,R49, R50,R51,R52,R58,R68,R69, R71,R72,R74,R85,R95,R117, R129,R130,R155,R156,R158, R160 [["49", "7", "RP13,RP15,RP17,RP19,RP24,RP32,RP33", "12X2", "33XD", "Wireless, Independent, 5%"], ["50", "4", "RP27,RP28,RP30,RP31 ", "10XC4", "3X567", "Network, Isolated, 5%"], ["51", "31", "R1,R2,R8,R30,R32,R33,R35,R37,R39,R41,R42,R43,R49,R50,R51,R52,R58,R68,R6 9,R71,R72,R74,R85,R95,R117,R129,R130,R155,R156,R158,R160", "0603,R10K, 1%", "0603", "3%,1/12W"]] Regards, Morton