On Aug 16, 2007, at 2:35 PM, William James wrote:

> This is the best I've come up with so far.  It should handle any CSV
> record
> (i.e., fields may contain commas, double quotes, and newlines).
>
> class String
>   def csv
>     if include? '"'
>       ary =
>         "#{chomp},".scan( /\G"([^"]*(?:""[^"]*)*)",|\G([^,"]*),/ )
>       raise "Bad csv record:\n#{self}"  if $' != ""
>       ary.map{|a| a[1] || a[0].gsub(/""/,'"') }
>     else
>       ary = chomp.split( /,/, -1)
>       ##   "".csv ought to be [""], not [], just as
>       ##   ",".csv is ["",""].
>       if [] == ary
>         [""]
>       else
>         ary
>       end
>     end
>   end
> end

You are pretty much rewriting FasterCSV here.  Why do that when we  
could just use it instead?

James Edward Gray II