C# Class Kajabity.Tools.Csv.CsvReader

This class reads CSV formatted data from an input stream. It can read individual fields in a row, a full row or the whole file. Data can only be read once - so if the first field in a row is read, it won't be part of the row if that is read next. The term Row is used rather than line because quoted fields can include line breaks (real, not escaped) so that one row may be spread across multiple lines.
显示文件 Open project: Kajabity/Kajabity-Tools Class Usage Examples

Public Properties

Property Type Description
Quote int
Separator int

Public Methods

Method Description
CsvReader ( Stream stream ) : System.Collections

Construct a inStream.

ReadAll ( ) : string[][]

Reads all fields and records from the CSV input stream from the current location.

ReadField ( ) : string

Reads the next field on the current line - or null after the end of the line. The field will not be part of the next ReadLine or ReadFile.

ReadRecord ( ) : string[]

Read to the end of the current record, if any.

Private Methods

Method Description
DoAction ( int action, int ch ) : void

Performs the action associated with a state transition.

Matches ( int match, int ch ) : bool

Tests if the current character matches a test (one of the MATCH_* tests).

NextChar ( ) : int

Returns and removes the next character from the input stream - including any that have been peeked and pushed back.

Parse ( int finalSate ) : void

Parse the input CSV stream from the current position until the final state is reached. Intended to allow parsing to End of Field, End of Record or End of File.

PeekChar ( ) : int

Retuns but doesn't remove the next character from the stream. This character will be returned every time this method is called until it is returned by NextChar().

Method Details

CsvReader() public method

Construct a inStream.
public CsvReader ( Stream stream ) : System.Collections
stream System.IO.Stream The input stream to read from.
return System.Collections

ReadAll() public method

Reads all fields and records from the CSV input stream from the current location.
public ReadAll ( ) : string[][]
return string[][]

ReadField() public method

Reads the next field on the current line - or null after the end of the line. The field will not be part of the next ReadLine or ReadFile.
public ReadField ( ) : string
return string

ReadRecord() public method

Read to the end of the current record, if any.
public ReadRecord ( ) : string[]
return string[]

Property Details

Quote public_oe property

Gets or sets the quote character used in the CSV stream - default value is a double quote ('"').
public int Quote
return int

Separator public_oe property

Gets or sets the separator character used in the CSV stream - default value is a comma (',').
public int Separator
return int