解析CSV文件时忽略标题行 [英] Ignore header line when parsing CSV file

查看:1113
本文介绍了解析CSV文件时忽略标题行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在CSV文件的标题行在ruby在rails上忽略,同时进行CSV解析!任何想法

How can the header line of the CSV file be ignored in ruby on rails while doing the CSV parsing!! Any ideas

推荐答案

我找到了上述问题的解决方案。这是我在ruby 1.9.X中做的方式。

I have found the solution to above question. Here is the way i have done it in ruby 1.9.X.

csv_contents = CSV.parse(File.read(file))
csv_contents.slice!(0)
csv=""
csv_contents.each do |content|
    csv<<CSV.generate_line(content)
end

这篇关于解析CSV文件时忽略标题行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆