fasterCSV操作

[color=red]fasterCSV [/color]
This class provides a complete interface to CSV files and data. It offers tools to enable you to read and write to and from Strings or IO objects, as needed.
[color=red][b]读[/b] [/color]
1.从一个文件读 每次读取一行
FasterCSV.foreach("path/to/file.csv") do |row| # use row here... end

全部读取
arr_of_arrs = FasterCSV.read("path/to/file.csv") 

2.从字符串里读
A Line at a Time
FasterCSV.parse("CSV,data,String") do |row| 
# use row here... end

All at Once
arr_of_arrs = FasterCSV.parse("CSV,data,String") 

[color=red][b]写[/b][/color]
To a File
FasterCSV.open("path/to/file.csv", "w") do |csv|
csv << ["row", "of", "CSV", "data"]
csv << ["another", "row"]
# ... end

To a String

csv_string = FasterCSV.generate do |csv|
csv << ["row", "of", "CSV", "data"]
csv << ["another", "row"]
# ... end

Convert a Single Line
csv_string = ["CSV", "data"].to_csv # to CSV 
csv_array = "CSV,String".parse_csv # from CSV
Shortcut Interface
  
FCSV { |csv_out| csv_out << %w{my data here} } # to $stdout
FCSV(csv = "") { |csv_str| csv_str << %w{my data here} } # to a String
FCSV($stderr) { |csv_err| csv_err << %w{my data here} } # to $stderr

原文:[url]http://fastercsv.rubyforge.org/[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值