[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

fastercsv and several row

Li Chen

7/22/2008 6:10:00 PM

Hi all,

I just try fastercsv and it works fine.

I use the codes below to print out the first columns of the first ten
rows. And it is OK. Question1) Is this the Ruby way to do that?
Question 2)what if I want to print out the first columns of row 20-30?


Thank you very much,

Li

####
i=1
FasterCSV.foreach('test.csv','rb') do |row|
puts row[0]
break if i==10
i+=1
end
####
--
Posted via http://www.ruby-....

5 Answers

ElParedon

1/21/2008 2:51:00 PM

0


"RJ11" <rj11@nospam.com> wrote in message news:fmtplj$59c$1@pcls6.std.com...
> In article <7JadnZDzLZmW2AzanZ2dnUVZ_oWdnZ2d@giganews.com>,
> B'in'yamin C'r'amer <hebesRturdz@best.com> wrote:
>
> (angry rants snipped)
>
> Still upset that your side lost, doper?

Whi won? Certainly not the Jews or USA for that matter


James Gray

7/22/2008 6:23:00 PM

0

On Jul 22, 2008, at 1:09 PM, Li Chen wrote:

> Hi all,

Hello.

> I just try fastercsv and it works fine.

Great.

> I use the codes below to print out the first columns of the first ten
> rows. And it is OK. Question1) Is this the Ruby way to do that?

It's definitely one possible way. You could also use:

FCSV.open('test.csv') do |csv|
csv.each do |row|
puts row.first
break if csv.lineno >= 10
end
end

> Question 2)what if I want to print out the first columns of row
> 20-30?

FCSV.open('test.csv') do |csv|
csv.each do |row|
puts row.first if csv.lineno >= 20
break if csv.lineno >= 30
end
end

Hope that gives you some fresh ideas.

James Edward Gray II

Li Chen

7/22/2008 6:34:00 PM

0

Hi James,

Thank you very much. But where can I find description about method
row.first and csv.lineno in the document?


Li
--
Posted via http://www.ruby-....

James Gray

7/22/2008 6:41:00 PM

0

On Jul 22, 2008, at 1:33 PM, Li Chen wrote:

> Thank you very much. But where can I find description about method
> row.first and csv.lineno in the document?

http://www.ruby-doc.org/core/classes/Array.ht...

http://fastercsv.rubyforge.org/classes/Fast... (look in the
Attributes section)

James Edward Gray II

Li Chen

7/22/2008 7:08:00 PM

0

James Gray wrote:

> http://www.ruby-doc.org/core/classes/Array.ht...
>
> http://fastercsv.rubyforge.org/classes/Fast... (look in the
> Attributes section)
>
> James Edward Gray II

Thank you very much. They are really sweet.

Li

--
Posted via http://www.ruby-....