From: Jiawei Yong Date: 2011-01-25T14:58:34+09:00 Subject: Re: Obtain data from .csv Kamarulnizam Rahim wrote in post #977296: > Sample of .csv file: > > ["Issue,,Risk/Opportunity,Compliance,Consequence,Current Status,Due > Date,Priority,Responsibility,Probability"] > ["1,Efficiency (Energy),No > Action,Unknown,Neutral,Active,,Medium,,Possible"] > ["Action,,Cost,Status,Due Date,Responsibility,,,,"] > ["1.a,Maximise use of natural lighting,,Active,,,,,,"] > ["1.b,Turn-off unnecessary lights/equipment,,Active,,,,,,"] > ["1.c,Install energy efficient lighting,,Active,,,,,,"] > ["1.d,Turn-off unnecessary air conditioning,,Active,,,,,,"] > > Using the following code: > > f = File.open("ActionPlan.csv", "r") > f.each_line { |line| > fields = line.split(',') > #......... > } > > Anyone knows how to use ruby code to obtain the following data(question) > from the file? > > > But dont know how to obtain the rest of the data. Any help would be > great. Thanks in advance > > Nizam Hi Nizam, Sorry to say but I think I'm quite confused. You started out trying CSV and have another thread on that, but with this thread it seems you have decided to give up on that approach and use simple lines and split. Unfortunately I'm still getting nowhere closer to what you actually intend to do with your data once you have broken it down into individual fields. Just a point to note... in the other thread, where 1 of the solution is to use regexp to split each line down into individual sections, is made based on the assumption your delimiter is '|'. Maybe you can try to change that piece of code to split on ',' and try printing out the fields again and see if it works. yjw -- Posted via http://www.ruby-forum.com/.