Difference between revisions of "CsvReader class"
(Created page with "{{CGscriptClass_Template |Name=<nowiki>CsvReader</nowiki> |Description=<nowiki>Represents a reader that provides fast, non-cached, forward-only access to CSV data.</nowiki> |Cons...") |
(No difference)
|
Revision as of 10:06, 22 September 2011
CsvReader
Represents a reader that provides fast, non-cached, forward-only access to CSV data.
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
- string 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.
- string this[] { get; }(number 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.
- string ToString() - The string representation of the object.
Properties
- number 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.
- TypeInformation TypeInformation { get; } - Get information about this class.