Ruby CSV - get current line/row number

前端 未结 4 2045
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 05:51

I\'m trying to work out how to get the current line/row number from Ruby CSV. This is my code:

options = {:encoding => \'UTF-8\', :skip_blanks => true}         


        
4条回答
  •  攒了一身酷
    2020-12-13 06:29

    Here's an alternative solution:

    options = {:encoding => 'UTF-8', :skip_blanks => true}
    
    CSV.foreach("data.csv", options).with_index do |row, i|
       puts i
    end
    

提交回复
热议问题