From: Li Chen Date: 2009-09-28T22:38:49+09:00 Subject: format problem Hi all, I have an 2D array and I write it a file using the following script. But when I open the written file I find the format is not what I want: the second and third row are not justified as the first row. I wonder how to correct it. Thanks, Li ############ c=[ ['a','b','c'],['c1',2,1],['d1',3,4] ] c.collect!{|row| row<<"\n"} File.open('test.txt','w') do |a_file| c.each do |row| row.each {|e| ("#{e}"=~/[a-zA-Z]|\n/) ? (a_file.printf("%s\t",e)) : ( a_file.printf("%.2f\t",e)) } end end ########output############# a b c c1 2.00 1.00 d1 3.00 4.00 ####expected as follow######## a b c c1 2.00 1.00 d1 3.00 4.00 -- Posted via http://www.ruby-forum.com/.