From: Chen Ge Date: 2010-04-11T14:52:43+09:00 Subject: Re: how to write array value into csv file? Pen Ttt wrote: > how to write array value into csv file? > there is array a: > a[0]=date;asset;cash;finance;note; > a[1]=2009-12-31;580;1,693;201;500; > a[2]=2009-09-30; 680;1,777;2497;700; > i want to get array a into csv files as the following: > > csvfile1: > date 2009-12-31 2009-09-30 > asset 580 680 > cash 1,693 1,777 > finance 201 2497 > note 500 700 > csvfile2: > date asset cash finance note > 2009-12-31 580 1,693 201 500 > 2009-09-30 680 1,777 2497 700 > > how can i do? a=[] a[0]='date;asset;cash;finance;note;' a[1]='2009-12-31;580;1,693;201;500;' a[2]='2009-09-30; 680;1,777;2497;700;' file=File.new('csv2.csv','w') for e in a do str_array=e.split(';') for x in str_array do file.write x + "\t\t\t" end file.puts end #output to csv2 file -- Posted via http://www.ruby-forum.com/.