CsvReader class

From Catglobe Wiki
Jump to: navigation, search

CsvReader



Represents a reader that provides fast, non-cached, forward-only access to CSV data.

Parent class

Inherits from object

Constructors

  • (string csvData "The string containing the text to be parsed as csv data", bool hasHeaders "true if field names are located on the first non commented line, otherwise, false.", string delimiter "The delimiter character separating each field (default is ',').", string quote "The quotation character wrapping every field (default is ''').", string escape "The escape character letting insert quotation characters inside a quoted field (default is '\'). If no escape character, set to '\0' to gain some performance.", string comment "The comment character indicating that a line is commented out (default is '#').", bool skipEmptyLines "A value indicating if the reader will skip empty lines.", bool supportsMultiline "A value indicating if the reader supports multiline field.") - Create a new reader. Example: string empt = empty; CsvReader csv = new CsvReader(csvData, true, ";", "\"", empt, empt, true, false); number fieldCount = csv.FieldCount; array headers = csv.Headers; while(csv.ReadNextRecord()) { for(number i = 0; i < fieldCount; i = i +1) { string value = csv[i]; if (value == empty) value = "MISSING"; print(headers[i] + " = " + value); } print("---------"); }

Methods

  • object this[] { get; }(string field "The field with the specified name.") - Gets the field with the specified name. Must have set hasHeaders to true when starting read.
  • object this[] { get; }(int field "The field at the specified index.") - Gets the field at the specified index.
  • bool ReadNextRecord() - Reads the next record. true if a record has been successfully reads; otherwise, false.
  • (From object) string ToString() - The string representation of the object.

Properties

  • int FieldCount { get; } - Gets the maximum number of fields to retrieve for each record.
  • array Headers { get; } - Gets the field headers.
  • string ObjectTypeName { get; } - The name of the type of object.
  • (From object) TypeInformation TypeInformation { get; } - Get information about this class.


Examples

string empt = empty;
CsvReader csv = new CsvReader(csvData, true, ";", "\"", empt, empt, true, false);
number fieldCount = csv.FieldCount;
array headers = csv.Headers;
while(csv.ReadNextRecord())
{
    for(number i = 0; i < fieldCount; i = i +1) 
    {
       string value = csv[i];
       if (value == empty) value = "MISSING";
       print(headers[i] + " = " + value);
    }
    print("---------");
}