首页 > 代码库 > Ruby--CSV

Ruby--CSV

1. 解析CSV:

(1)读取文件:csv = CSV.read("#{Rails.root}/public/data/statecountycity.csv", :headers => true, :header_converters => lambda{|h| h.strip})

(2)遍历:csv.each do |row| {c_row = row.to_hash ......}

Ruby--CSV