[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: CVS parsing, counting rows and row items

James Gray

9/12/2007 3:09:00 PM

On Sep 12, 2007, at 9:57 AM, Felix Windt wrote:

> If all you want to do is count rows in a CSV file, you're just
> counting
> lines in a file and don't need the CSV library.

CSV fields can contain line ending characters which could throw of
your counts. Use a CSV parser unless you are sure about the data
content.

James Edward Gray II

1 Answer

Max Russell

9/12/2007 3:39:00 PM

0

James Gray wrote:
> On Sep 12, 2007, at 9:57 AM, Felix Windt wrote:
>
>> If all you want to do is count rows in a CSV file, you're just
>> counting
>> lines in a file and don't need the CSV library.
>
> CSV fields can contain line ending characters which could throw of
> your counts. Use a CSV parser unless you are sure about the data
> content.
>
> James Edward Gray II

def parsecv(filehandle)
csvarrays = CSV.read(filehandle)
numrows = (csvarrays.length) - 1
return numrows
end

I ended up using a CSV.read method because it returns an array of
arrays. This makes it quite easy to lop of the titles row returning a
row count.

Now to start getting the count of individual terms from a column...
--
Posted via http://www.ruby-....