struct CSV

Structure for working with CSV-tables.

this(string filepath)

The constructor takes a path to CSV-file.

this(string[][] table)

The constructor takes a two-dimensional array as the initiating table.

this(string filepath, string[][] table)

The constructor takes a path to future CSV-file and two-dimensional array as the initiating table.

Parameters

filepath

Path to file for saving CSV table. The existence of the file, as well as its contents, do not matter.

table

2D array with content for the CSV file.

this(string[] keys, string[][] table)

The constructor takes an array of table column names and a two-dimensional array as the initiating table.

Parameters

keys

Table column titles.

table

2D with content for the CSV file (without titles).

string[][] getTable() const

The method returns content of the table of the CSV-object as two-dimensional array.

string[string][] getArrayOfRowMaps() const

The method returns rows of the table as associative arrays, where keys are names of the columns and values are content of the fields.

string getValueOfField(string key1, string value, string key2) const

Finds the table field by another field in the same row (key1 and value) and column name (key2). Returns first match only.

string[string] getRowMapByField(string key, string value) const

The method finds table row by field (by column name and value), returns associative array, where keys are names of columns and values are content of fields of this row.

void setValueOfField(string key1, string value1, string key2, string value2)

The method sets new value (value2) by other field in the same row and column name.

void addRow(string[] row)

The methods adds new table row.

void deleteRowByKeyAndValue(string key, string value)

The method deletes table row by field (by its key and value).

void rewrite() const

The method writes table content to the initiating file.

void writeTo(string filepath) const

The method writes table content to the specified file.

void createTable(string[][] table)

The two-dimensional array will be used as the content of the CSV table.

void createTable(string[] keys, string[][] table)

The two-dimensional array will be used as the content of the CSV table.

Parameters

keys

Titles for columns.

table

2D array for CSV fields.