Skip to content
xlson edited this page Nov 9, 2010 · 4 revisions

GroovyCSV - Documentation

Links

Parsing Options

CsvParser expects your csv to use the default separators, but what if it don't? No worries, there are settings for that. There are 3 options that you can set when parsing your csv. The options are sent as named params to the parse method like this: csvParser.parse(csv, separator: '-', quoteChar:"'")

Options

  • separator Sets a custom separator like tab (Defaults to ,)
  • quoteChar Sets a custom quote character (Defaults to ")
  • escapeChar Sets a custom escape character for the separator and quoteChar (Defaults to )

Sample

An example of parsing csv that uses - as separator and ' instead " as quoteChar.

import com.xlson.groovycsv.CsvParser

def csv = '''Name-Lastname
Mark-'Anderson-Nielsen'
Pete-Hansen'''

def data = new CsvParser().parse(csv, separator: '-', quoteChar: "'")
for(line in data) {
    println "$line.Name $line.Lastname"
}

** Output: **

Mark Anderson-Nielsen

Pete Hansen

Clone this wiki locally