IGLib  1.7.2
The IGLib base library for development of numerical, technical and business applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
IG.Lib.UtilCsv Class Reference

Auxiliary utilities for dealing with files in CSV and other delimited formats. More...

+ Inheritance diagram for IG.Lib.UtilCsv:

Static Public Member Functions

static bool CsvIsEmptyRow (string[][] values, int rowIndex)
 Returns true if the specified line in a 2D jagged array of string cell values (arranged in rows) is empty or does not exist, otherwise false is returned. More...
 
static string CsvGetValue (string[][] values, int rowIndex, int columnIndex)
 Returns the value of the specified cell of a 2D jagged array of string cell values (arranged in rows) at the specified row and column, or null if such a value does not exist. More...
 
static int CsvColumnIndex (string[][] values, string fieldName)
 Returns index of thr column that contains data with the specified name in a 2D jagged array of values. It is assumed that the first non-empty row (subarray) contains names of data columns. -1 is returned if the column with the specified field name is not found. Column (or field) names are assumed to be case insensitive. More...
 
static int CsvColumnIndex (string[][] values, string fieldName, bool caseSensitive)
 Returns index of thr column that contains data with the specified name in a 2D jagged array of values. It is assumed that the first non-empty row (subarray) contains names of data columns. -1 is returned if the column with the specified field name is not found. More...
 
static string[][] FromCsvString (string csvString)
 Converts a CSV string to a 2D jagged array of string values and returns it. Constant UtilCsv.DefaultCsvSeparator) is assumed to be a separator in the CSV format. More...
 
static string[][] FromCsvString (string csvString, string separator)
 Converts a CSV string to a 2D jagged array of string values and returns it. More...
 
static string ToCsvString (string[][] values, string separator)
 Convertsa a 2D jagged array of string values to a string in CSV format. More...
 
static string[][] LoadCsv (string filePath, string separator)
 Reads contents of a CSV file and returns a 2D jagged array of strigg values contained in the file. More...
 
static string[][] LoadCsv (string filePath)
 Reads contents of a CSV file and returns a 2D jagged array of strigg values contained in the file. Constant UtilCsv.DefaultCsvSeparator is assumed as separator in the CSV file. More...
 
static void SaveCsv (string filePath, string[][] values, string separator, bool append)
 Saves a 2D jagged array of string cell values into a CSV file. More...
 
static void SaveCsv (string filePath, string[][] values, string separator)
 Saves a 2D jagged array of string cell values into a CSV file. If the file already exists then its contents are overwritten. More...
 
static void SaveCsv (string filePath, string[][] values, bool append)
 Saves a 2D jagged array of string cell values into a CSV file. Constant UtilCsv.DefaultCsvSeparator is assumed to be a separator for the CSV format. More...
 
static void SaveCsv (string filePath, string[][] values)
 Saves a 2D jagged array of string cell values into a CSV file. If the file already exists then its contents are overwritten. Constant UtilCsv.DefaultCsvSeparator is assumed to be a separator for the CSV format. More...
 
static bool TestCsvStringConversion (string[][] values, string separator, bool printResults)
 Tests conversion of a 2D jagged array of string values to a CSV formatted string and back. Returns true if the array restored by conversion of the original array to a CSV string and back from a CSV string to a jagged array is the same (within inevitable ambiguities of the CSV format) as the original array. More...
 
static void ExampleCsv ()
 Example of using CSV format utilities. More...
 

Public Attributes

const string DefaultCsvSeparator = ","
 The default separator in the CSV files - comma (","). More...
 

Static Public Attributes

static string _csvSeparator = DefaultCsvSeparator
 

Static Protected Member Functions

static string TableToString (string[][] values, string valueSeparator)
 Returns a string that represents a table of string values. Each value is embedded in double quotes, values are separated by commas, and tables of values are separated by newlines. More...
 

Properties

static string CsvSeparator [get, set]
 

Detailed Description

Auxiliary utilities for dealing with files in CSV and other delimited formats.

CSV - related utilities were moved here from the UtilStr class on May 2013.

$A Igor xx May13;

Member Function Documentation

static bool IG.Lib.UtilCsv.CsvIsEmptyRow ( string  values[][],
int  rowIndex 
)
inlinestatic

Returns true if the specified line in a 2D jagged array of string cell values (arranged in rows) is empty or does not exist, otherwise false is returned.

Parameters
valuesA 2D jagged array that contains a table of tables (rows) of string cell values. Such array corresponds a table of rows of cells stored in CSV format.
rowIndexIndex of the line that is tested for being empty or not.

$A Igor Oct08;

static string IG.Lib.UtilCsv.CsvGetValue ( string  values[][],
int  rowIndex,
int  columnIndex 
)
inlinestatic

Returns the value of the specified cell of a 2D jagged array of string cell values (arranged in rows) at the specified row and column, or null if such a value does not exist.

Parameters
valuesA 2D jagged array that contains a table of tables (rows) of string cell values. Such array corresponds a table of rows of cells stored in CSV format.
rowIndexRow number.
columnIndexColumn number.
Returns

$A Igor Oct08;

static int IG.Lib.UtilCsv.CsvColumnIndex ( string  values[][],
string  fieldName 
)
inlinestatic

Returns index of thr column that contains data with the specified name in a 2D jagged array of values. It is assumed that the first non-empty row (subarray) contains names of data columns. -1 is returned if the column with the specified field name is not found. Column (or field) names are assumed to be case insensitive.

Parameters
valuesA 2D jagged array that contains a table of tables (rows) of string cell values. Such array corresponds a table of rows of cells stored in CSV format.
fieldNameName of the data column (field) whose column index is searched for.
Returns
Index of data column with the specified name. Column (or field) names are assumed to be contained in the first nonempty sub-array (row).

$A Igor Oct08;

static int IG.Lib.UtilCsv.CsvColumnIndex ( string  values[][],
string  fieldName,
bool  caseSensitive 
)
inlinestatic

Returns index of thr column that contains data with the specified name in a 2D jagged array of values. It is assumed that the first non-empty row (subarray) contains names of data columns. -1 is returned if the column with the specified field name is not found.

Parameters
valuesA 2D jagged array that contains a table of tables (rows) of string cell values. Such array corresponds a table of rows of cells stored in CSV format.
fieldNameName of the data column (field) whose column index is searched for.
caseSensitiveWhether column (field) names are case sensitive or not.
Returns
Index of data column with the specified name. Column (or field) names are assumed to be contained in the first nonempty subarray (row).

$A Igor Oct08;

static string [][] IG.Lib.UtilCsv.FromCsvString ( string  csvString)
inlinestatic

Converts a CSV string to a 2D jagged array of string values and returns it. Constant UtilCsv.DefaultCsvSeparator) is assumed to be a separator in the CSV format.

Parameters
csvStringA CSV string representing data in CSV format.
Returns
A 2D jagged array that contains a table of string cell values of the CSV string that is parsed. Each Subarray contains a single row of cells values.

$A Igor Oct08;

static string [][] IG.Lib.UtilCsv.FromCsvString ( string  csvString,
string  separator 
)
inlinestatic

Converts a CSV string to a 2D jagged array of string values and returns it.

Parameters
csvStringA CSV string representing data in CSV format.
separatorSeparator that is used in CSV format (usually , or ;). If null or empty string then Constant UtilCsv.DefaultCsvSeparator is taken.
Returns
A 2D jagged array that contains a table of string cell values of the CSV string that is parsed. Each Subarray contains a single row of cells values.

$A Igor Oct08;

static string IG.Lib.UtilCsv.ToCsvString ( string  values[][],
string  separator 
)
inlinestatic

Convertsa a 2D jagged array of string values to a string in CSV format.

Parameters
valuesdD table of string values that are written in CSV format.
separatorSeparator that is used to separate cell values. If null or empty string then Constant UtilCsv.DefaultCsvSeparator is taken.

If the value of any cell contains separators then it is embedded in double quotes.

$A Igor Oct08;

Referenced by IG.Lib.StringTable.ToString().

static string IG.Lib.UtilCsv.TableToString ( string  values[][],
string  valueSeparator 
)
inlinestaticprotected

Returns a string that represents a table of string values. Each value is embedded in double quotes, values are separated by commas, and tables of values are separated by newlines.

Parameters
valuesa 2D jagged array of string values that is converted to a string.
valueSeparatorSeparator that separates individual values in a row. If not specified then Constant UtilCsv.DefaultCsvSeparator is taken.
Returns
String containing values in double quotes, separated by commas and arrays of values separated by newlines, that can, for example, be printed to a console. An additional newline is added after the last array of values.

$A Igor Oct08;

static string [][] IG.Lib.UtilCsv.LoadCsv ( string  filePath,
string  separator 
)
inlinestatic

Reads contents of a CSV file and returns a 2D jagged array of strigg values contained in the file.

Parameters
filePathPath to the CSV file that is read and parsed.
separatorSeparator that is used in the CSV file. If not specified (null or empty string) then Constant UtilCsv.DefaultCsvSeparator is assumed.
Returns
A 2D jagged array that contains a table of string cell values of the CSV string that is parsed. Each Subarray contains a single row of cells values.

$A Igor Oct08;

References IG.Lib.UtilStr.Load().

Referenced by IG.Lib.StringTable.LoadCsv(), and IG.Num.VectorBase.LoadCsv().

static string [][] IG.Lib.UtilCsv.LoadCsv ( string  filePath)
inlinestatic

Reads contents of a CSV file and returns a 2D jagged array of strigg values contained in the file. Constant UtilCsv.DefaultCsvSeparator is assumed as separator in the CSV file.

Parameters
filePathPath to the CSV file that is read and parsed.
Returns
A 2D jagged array that contains a table of string cell values of the CSV string that is parsed. Each Subarray contains a single row of cells values.

$A Igor Oct08;

static void IG.Lib.UtilCsv.SaveCsv ( string  filePath,
string  values[][],
string  separator,
bool  append 
)
inlinestatic

Saves a 2D jagged array of string cell values into a CSV file.

Parameters
filePathPath to the file into which contents is written.
valuesA 2D jagged array of string cell values. Each outer element contains one row of values in CSV.
separatorSeparator that is used in CSV format.
appendIf true then the CSV string is appended to the existent file if the file already exists. Otherwise, existend files are overwritten.

References IG.Lib.UtilStr.Save().

Referenced by IG.Lib.StringTable.SaveCsv(), and IG.Num.VectorBase.SaveCsv().

static void IG.Lib.UtilCsv.SaveCsv ( string  filePath,
string  values[][],
string  separator 
)
inlinestatic

Saves a 2D jagged array of string cell values into a CSV file. If the file already exists then its contents are overwritten.

Parameters
filePathPath to the file into which contents is written.
valuesA 2D jagged array of string cell values. Each outer element contains one row of values in CSV.
separatorSeparator that is used in CSV format.

$A Igor Oct08;

static void IG.Lib.UtilCsv.SaveCsv ( string  filePath,
string  values[][],
bool  append 
)
inlinestatic

Saves a 2D jagged array of string cell values into a CSV file. Constant UtilCsv.DefaultCsvSeparator is assumed to be a separator for the CSV format.

Parameters
filePathPath to the file into which contents is written.
valuesA 2D jagged array of string cell values. Each outer element contains one row of values in CSV.
appendIf true then the CSV string is appended to the existent file if the file already exists. Otherwise, existend files are overwritten.
static void IG.Lib.UtilCsv.SaveCsv ( string  filePath,
string  values[][] 
)
inlinestatic

Saves a 2D jagged array of string cell values into a CSV file. If the file already exists then its contents are overwritten. Constant UtilCsv.DefaultCsvSeparator is assumed to be a separator for the CSV format.

Parameters
filePathPath to the file into which contents is written.
valuesA 2D jagged array of string cell values. Each outer element contains one row of values in CSV.

$A Igor Oct08;

static bool IG.Lib.UtilCsv.TestCsvStringConversion ( string  values[][],
string  separator,
bool  printResults 
)
inlinestatic

Tests conversion of a 2D jagged array of string values to a CSV formatted string and back. Returns true if the array restored by conversion of the original array to a CSV string and back from a CSV string to a jagged array is the same (within inevitable ambiguities of the CSV format) as the original array.

Parameters
valuesOriginal 2D jagged array of values arranged by rows, which is converted to a CSV string and back.
separatorSeparator that is used in CSV format (usually this will be "," or ";", sometimes "\t"). If not specified (null or empty string) then the Constant UtilCsv.DefaultCsvSeparator is assumed.
printResultsIf true then detailed results of the test are printed to a console, indicating all individual differences between the original and restored data. It is also indicated whether the individual differences are considered errors (if not then a string describing a difference begins with "WARNING").
Returns
True if the test has passed, i.e. the restored data obtained by conversion to a CSV string and back is the same (within allowed discrepancies) than original data.
static void IG.Lib.UtilCsv.ExampleCsv ( )
inlinestatic

Example of using CSV format utilities.

$A Igor Oct08;

Member Data Documentation

const string IG.Lib.UtilCsv.DefaultCsvSeparator = ","
string IG.Lib.UtilCsv._csvSeparator = DefaultCsvSeparator
static

Property Documentation

string IG.Lib.UtilCsv.CsvSeparator
staticgetset

The documentation for this class was generated from the following file: