Format delimited data into columns. Similar to the unix shell program column.
Some CSV file:
Date,Type,Description,Amount
30/10/2013,DEB,SUPERMARKET 29833,5.15
29/10/2013,DEB,AMAZON MKPLACE,5.63
Parse the file:
var result = golumn.parse(string(data), ",", golumn.Options{
MaxColumnWidth: 5,
Truncate: true,
})
print(result)Prints the following:
Date Type Descr Amoun
30/1 DEB SUPER 5.15
29/1 DEB AMAZO 5.63
Download and compile the source with go get github.com/st3redstripe/golumn. Then import as usual.
import (
"github.com/st3redstripe/golumn"
)Call Parse passing in an input string and a delimiter.
func Parse(input string, delim string) stringUse ParseF to override default options.
func ParseF(input string, delim string, options Options) stringFor use with ParseF - where options is a golumn.Options struct containing a subset of the following
ColumnSpacerstring- The characters used to pad columns, default is\t.NewLinestring- New line character, default is\n.ColumnWidthint- Sets colums to be a fixed width.MaxColumnWidthint- Constrains column widths. Overidden if a validColumnWidthoption is given.Truncatebool- Truncates any cells that overflow theColumnWidthorMaxColumnWidth.