| IGLib 1.7.2 The IGLib base library for development of numerical, technical and business applications.

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
Static Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Member Functions | Properties | List of all members
IG.Lib.UtilCsv Class Reference

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

Inheritance diagram for IG.Lib.UtilCsv:
[legend]

## 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
| ) |  |
| inline static

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

  values | A 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.
  rowIndex | Index 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
| ) |  |
| inline static

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

  values | A 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.
  rowIndex | Row number.
  columnIndex | Column number.

Returns

$A Igor Oct08;

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

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

  values | A 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.
  fieldName | Name 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
| ) |  |
| inline static

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

  values | A 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.
  fieldName | Name of the data column (field) whose column index is searched for.
  caseSensitive | Whether 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 | ) |
| inline static

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

  csvString | A 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
| ) |  |
| inline static

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

Parameters

  csvString | A CSV string representing data in CSV format.
  separator | Separator 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
| ) |  |
| inline static

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

Parameters

  values | dD table of string values that are written in CSV format.
  separator | Separator 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
| ) |  |
| inline static protected

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

  values | a 2D jagged array of string values that is converted to a string.
  valueSeparator | Separator 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
| ) |  |
| inline static

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

Parameters

  filePath | Path to the CSV file that is read and parsed.
  separator | Separator 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 | ) |
| inline static

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

  filePath | Path 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
| ) |  |
| inline static

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

Parameters

  filePath | Path to the file into which contents is written.
  values | A 2D jagged array of string cell values. Each outer element contains one row of values in CSV.
  separator | Separator that is used in CSV format.
  append | If 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
| ) |  |
| inline static

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

Parameters

  filePath | Path to the file into which contents is written.
  values | A 2D jagged array of string cell values. Each outer element contains one row of values in CSV.
  separator | Separator that is used in CSV format.

$A Igor Oct08;

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

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

  filePath | Path to the file into which contents is written.
  values | A 2D jagged array of string cell values. Each outer element contains one row of values in CSV.
  append | If 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[][]
| ) |  |
| inline static

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

  filePath | Path to the file into which contents is written.
  values | A 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
| ) |  |
| inline static

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

  values | Original 2D jagged array of values arranged by rows, which is converted to a CSV string and back.
  separator | Separator 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.
  printResults | If 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 | ( |  | ) |
| inline static

Example of using CSV format utilities.

$A Igor Oct08;

## Member Data Documentation

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

The default separator in the CSV files - comma (",").

Referenced by IG.Num.ScalarFunctionScriptControllerBase< ScalarFunctionType >.LoadCsv(), IG.Num.VectorBase.LoadCsv(), IG.Num.ScalarFunctionScriptControllerBase< ScalarFunctionType >.SaveCsv(), and IG.Num.VectorBase.SaveCsv().

string IG.Lib.UtilCsv._csvSeparator = DefaultCsvSeparator
| static

## Property Documentation

string IG.Lib.UtilCsv.CsvSeparator
| static get set

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

- igbase/0guests/Tako78/UtilCsv.cs