On 12/2/06, William James <w_a_x_man / yahoo.com> wrote:
> Gregory Brown wrote:
> > On 12/2/06, jansenh <henning.jansen / gmail.com> wrote:
> > > hi comp.lang.ruby
> > >
> > > what is the ruby-way of comma separating the output from array.to_s?
> >
> > some_array.join(",")
> >
> > but if you are thinking of doing CSV output, you should not use a
> > naive approach like this, since it will likely produce malformed CSV
> > when dealing with quoted text.
>
>
> >> puts [22,'He said, "No!"'].map{|x| x=x.to_s
> >>   x =~ /["\n]/ ? '"' + x.gsub(/"/,'""') + '"' : x }.join(',')
> 22,"He said, ""No!"""

Yeah, now deal with edge cases, and try to run that on 100k rows :)