Difference between revisions of "CsvReader class"

From Catglobe Wiki
Jump to: navigation, search
 
Line 2: Line 2:
 
|Name=<nowiki>CsvReader</nowiki>
 
|Name=<nowiki>CsvReader</nowiki>
 
|Description=<nowiki>Represents a reader that provides fast, non-cached, forward-only access to CSV data.</nowiki>
 
|Description=<nowiki>Represents a reader that provides fast, non-cached, forward-only access to CSV data.</nowiki>
|Constructors=
+
|InheritsFrom=object|Constructors=
 
{{CGscriptConstructors_Template|Parameters=
 
{{CGscriptConstructors_Template|Parameters=
 
{{CGscriptParameters_Template|Type=string|Name=<nowiki>csvData</nowiki>|Description=<nowiki>The string containing the text to be parsed as csv data</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>hasHeaders</nowiki>|Description=<nowiki>true if field names are located on the first non commented line, otherwise, false.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>delimiter</nowiki>|Description=<nowiki>The delimiter character separating each field (default is ',').</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>quote</nowiki>|Description=<nowiki>The quotation character wrapping every field (default is ''').</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>escape</nowiki>|Description=<nowiki>The escape character letting insert quotation characters inside a quoted field (default is '\'). If no escape character, set to '\0' to gain some performance.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>comment</nowiki>|Description=<nowiki>The comment character indicating that a line is commented out (default is '#').</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>skipEmptyLines</nowiki>|Description=<nowiki>A value indicating if the reader will skip empty lines.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>supportsMultiline</nowiki>|Description=<nowiki>A value indicating if the reader supports multiline field.</nowiki>}}
 
{{CGscriptParameters_Template|Type=string|Name=<nowiki>csvData</nowiki>|Description=<nowiki>The string containing the text to be parsed as csv data</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>hasHeaders</nowiki>|Description=<nowiki>true if field names are located on the first non commented line, otherwise, false.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>delimiter</nowiki>|Description=<nowiki>The delimiter character separating each field (default is ',').</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>quote</nowiki>|Description=<nowiki>The quotation character wrapping every field (default is ''').</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>escape</nowiki>|Description=<nowiki>The escape character letting insert quotation characters inside a quoted field (default is '\'). If no escape character, set to '\0' to gain some performance.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>comment</nowiki>|Description=<nowiki>The comment character indicating that a line is commented out (default is '#').</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>skipEmptyLines</nowiki>|Description=<nowiki>A value indicating if the reader will skip empty lines.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>supportsMultiline</nowiki>|Description=<nowiki>A value indicating if the reader supports multiline field.</nowiki>}}
|Description=<nowiki>Create a new reader.</nowiki>}}
+
|Description=<nowiki>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("---------");
 +
}
 +
</nowiki>}}
 
|Methods=
 
|Methods=
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
+
{{CGscriptMethods_Template|ReturnType=object|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
 
{{CGscriptParameters_Template|Type=string|Name=<nowiki>field</nowiki>|Description=<nowiki>The field with the specified name.</nowiki>}}
 
{{CGscriptParameters_Template|Type=string|Name=<nowiki>field</nowiki>|Description=<nowiki>The field with the specified name.</nowiki>}}
 
|Description=<nowiki>Gets the field with the specified name. Must have set hasHeaders to true when starting read.</nowiki>}}
 
|Description=<nowiki>Gets the field with the specified name. Must have set hasHeaders to true when starting read.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
+
{{CGscriptMethods_Template|ReturnType=object|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=number|Name=<nowiki>field</nowiki>|Description=<nowiki>The field at the specified index.</nowiki>}}
+
{{CGscriptParameters_Template|Type=int|Name=<nowiki>field</nowiki>|Description=<nowiki>The field at the specified index.</nowiki>}}
 
|Description=<nowiki>Gets the field at the specified index.</nowiki>}}
 
|Description=<nowiki>Gets the field at the specified index.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>ReadNextRecord</nowiki>|Description=<nowiki>Reads the next record. true if a record has been successfully reads; otherwise, false.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>ReadNextRecord</nowiki>|Description=<nowiki>Reads the next record. true if a record has been successfully reads; otherwise, false.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Description=<nowiki>The string representation of the object.</nowiki>}}
+
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Inherited=object|Description=<nowiki>The string representation of the object.</nowiki>}}
 
|Properties=
 
|Properties=
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>FieldCount</nowiki>|HasGetter=1|Description=<nowiki>Gets the maximum number of fields to retrieve for each record.</nowiki>}}
+
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>FieldCount</nowiki>|HasGetter=1|Description=<nowiki>Gets the maximum number of fields to retrieve for each record.</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=array|Name=<nowiki>Headers</nowiki>|HasGetter=1|Description=<nowiki>Gets the field headers.</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=array|Name=<nowiki>Headers</nowiki>|HasGetter=1|Description=<nowiki>Gets the field headers.</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}}
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}}
+
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Inherited=object|Description=<nowiki>Get information about this class.</nowiki>}}
 
}}
 
}}
  

Latest revision as of 08:55, 2 July 2020

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("---------");
}