Hi, Am Sonntag, 30. Jan 2005, 17:35:49 +0900 schrieb Tim Sutherland: > In article <1107042295.816570.61420 / z14g2000cwz.googlegroups.com>, mepython > wrote: > [...] > >How hard to do reverse: create csv string from list? > > > >Thanks. I just started Ruby couple of days ago, so I am learning > >instead of implementing, Sorry. > > This assumes the input is an array of lines. (Where each line is an array.) > > class Array > def to_csv > map { |line| > line.map { |cell| > '"' + cell.gsub(/"/, '""') + '"' > }.join(',') > }.join("\n") > end > end How about this (untested): class Array def to_csv sep = ';' quo = '"' map { |line| line.map { |cell| c = cell.to_s if c.include? sep or c.include? quo quo + c.gsub( quo, quo*2) + quo else c end }.join sep }.join $/ end end Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de