11
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rubyで配列をCSVに書き込み,読み込み

Last updated at Posted at 2018-06-12

##何かしらの配列(array)をCSV(hoge.csv)へ書き込み

配列を一つ一つ**.each**で書き込んでいくイメージ

   CSV.open('hoge.csv','w') do |csv| # output to csv file
         array.each do |bo|
             csv << bo
         end        
    end

##CSV(hoge.csv)を配列(array)に読み込んで格納する

    CSV.foreach("hoge.csv") do |line|
        p line #一行ずつ出力する
        array.push(line) # arrayに格納する
    end

書き方はたくさんあるし,書きやすいコードを見つけてください!

11
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?