From: 7stud -- Date: 2012-12-07T12:24:06+09:00 Subject: Re: Rows and columns in a text file. Joao Silva wrote in post #1088123: > > f = File.new ("names1.txt", "r") > #j = File.new ("names2.txt", "w+") > a = [] > b = [] > > f.each do |line| >    a.push(line) > end > f.close > > rows = 7 > columns = 8 > > for i in 0..rows-1 >    for j in 0..columns-1 >    b.push(a[i][j]) > end > > puts b > > ######################################################################## > > The issue is that I find the way the words are written horizontally, if > I try to access their values ​​one by one, it seems that the place > properly, but if I use a cycle does not work. > > Thanks results = [] rows = 9 columns = 8 File.open ("data.txt") do |f| lines = f.readlines (0...columns).each do |column| string = "" (0...rows).each do |row| next if lines[row][column] == " " string << lines[row][column] end results.push string end end p results --output:-- ["NAMEONE", "NAMETWO", "NAMETHREE", "NAMEFOUR", "NAMEFIVE", "NAMESIX", "NAMESEVEN", "NAMEEIGTH"] -- Posted via http://www.ruby-forum.com/.