use CSV alongside the File class : csv « Development « Ruby






use CSV alongside the File class



require 'csv'
people = CSV.parse(File.read('text.txt'))
puts people[0][0]
puts people[1][0]
puts people[2][0]

//File: text.txt
F,M,M,45
L,C,F,23
D,P,F,38

 








Related examples in the same category

1.Read CSV file
2.Update a CSV file
3.Parse one CSV file line
4.Create data for CSV file
5.Reading and Searching CSV Data
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