We Recommend

Pro Apache Pro Apache
In addition to installation, maintenance, and deployment, the book demonstrates how to configure Apache to use Perl, PHP, and Python as server-side scripting languages. And unlike other books on Apache, Pro Apache provides comprehensive information on both major revisions - 1.3 and 2.0 - of the software.


Ballyhoo


Posted By

roock on 02/18/08


Tagged

list format csv


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

melling


CSV formatter


Published in: Groovy 


Format a list of lists to CSV format


  1. class CsvFormat {
  2.  
  3. def convertListToCsv(list) {
  4. def result = ''
  5. list.each{row ->
  6. row.each{col -> result += col + ','}
  7. result = result[0..-2]
  8. result += '\n'
  9. }
  10. result
  11. }
  12.  
  13. }
  14.  
  15.  
  16.  
  17. class CsvFormatTest extends GroovyTestCase {
  18.  
  19. void testConvertsListToCsv() {
  20. assertEquals '1,2\n3,4\n', new CsvFormat().convertListToCsv([[1,2],[3,4]])
  21. }
  22.  
  23. }

Report this snippet 

You need to login to post a comment.