Parse one CSV file line : csv « Development « Ruby






Parse one CSV file line



require 'csv'

file_str = File.open("data.csv").read
rec = []; pos=nil; i=-1
c,pos = CSV::parseLine(file_str,
                       pos.to_i,
                       rec[(i+=1)]=[]) until pos == 0

 








Related examples in the same category

1.Read CSV file
2.Update a CSV file
3.Create data for CSV file
4.Reading and Searching CSV Data
5.use CSV alongside the File class
6.loading the data from a CSV-formatted file into an array is with CSV.read:
7.pick out the first person in the data called Laura:
8.find the people in your database whose ages are between 20 and 40:
9.Saving Data Back to the CSV File