Libraries
Csv Source Code
 previous   up   next 

Function Summary
string
toCsvLine (in array string: data, in char: separator)
Convert an array of strings to a CSV line.
array string
fromCsvLine (in string: csvLine, in char: separator)
Convert a CSV line to an array of strings.
array string
readCsvLine (inout file: inFile, in char: separator)
Read the fields of a CSV line with a given separator from a file.

Function Detail

toCsvLine

const func string: toCsvLine (in array string: data, in char: separator)

Convert an array of strings to a CSV line. In a CSV line the fields are separated by the separator character. Fields that contain separator characters, double quotes, linefeeds or carriage returns are enclosed in double quotes ("). Double quotes inside a double quoted field are represented by doubling them (e.g.: The double quoted field "a""b" has the value a"b ).

Parameters:
data - String array to be converted.
separator - Separator character to be used in the CSV line.
Returns:
the CSV line created from ta data array.

fromCsvLine

const func array string: fromCsvLine (in string: csvLine, in char: separator)

Convert a CSV line to an array of strings. CSV fields in the CSV line are delimited by the separator character or the beginning or the end of the CSV line. A CSV field might be enclosed in double quotes ("). A double quoted CSV field might contain separator characters, double quotes (") or linefeed characters. Double quotes inside a double quoted field are represented by doubling them (e.g.: The double quoted field "a""b" has the value a"b ). This function is intended to be used, if the CSV line is already in a string. To read CSV lines from a file the function readCsvLine should be used instead of a combination of getln and fromCsvLine. The function readCsvLine allows to read CSV fields, which contain linefeed characters.

Parameters:
csvLine - CSV line to be converted.
separator - Separator character used in the CSV line.
Returns:
the array of CSV fields from the CSV line.
Raises:
RANGE_ERROR - If csvLine is not in CSV format.

readCsvLine

const func array string: readCsvLine (inout file: inFile, in char: separator)

Read the fields of a CSV line with a given separator from a file. CSV fields are delimited by the separator character or the beginning or the end of a CSV line. A CSV line is terminated with '\n', "\r\n" or EOF. A CSV field might be enclosed in double quotes ("). A double quoted CSV field might contain separator characters, double quotes (") or linefeed characters. Double quotes inside a double quoted field are represented by doubling them (e.g.: The double quoted field "a""b" has the value a"b ). For UTF-8 encoded CSV files there are two possibilities:

  • If the CSV file has been opened with openUtf8 the CSV fields will contain Unicode data.
  • If the file has been opened with open the CSV fields will contain UTF-8 encoded data. In this case the function fromUtf8 must be used, to convert each CSV field from the result array.
Parameters:
inFile - File from which the CSV line is read.
separator - Separator character used in the CSV line.
Returns:
the array of CSV fields from the CSV line.
Raises:
RANGE_ERROR - If the CSV line is not in CSV format.


 previous   up   next