Class CsvReader
Parses CSV encoded rows from text.
Namespace: Neon.Csv
Assembly: Neon.Common.dll
Syntax
public sealed class CsvReader
Remarks
Use this class to parse CSV encoded tables. Use one of the constructors to initialize in instance to read from a file, Stream , string, or a TextReader and then call Read() to read each row of the table.
This class handles the all special cases for CSV parsing including quoted fields, escaped double quotes, and fields that include CR and LF characters.
Be sure to call Close() or Dispose() when you are finished with the class to release any underlying resources.
note
The underlying stream must support seeking for this class to work properly.
Constructors
CsvReader(Stream, Encoding)
Constructs a reader to parse a stream.
Declaration
public CsvReader(Stream stream, Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The input stream. |
Encoding | encoding | The stream's character Encoding. |
CsvReader(TextReader)
Constructs a reader to parse text from a TextReader.
Declaration
public CsvReader(TextReader reader)
Parameters
Type | Name | Description |
---|---|---|
TextReader | reader | The TextReader. |
CsvReader(string)
Constructs a reader to parse a string.
Declaration
public CsvReader(string text)
Parameters
Type | Name | Description |
---|---|---|
string | text | The text string. |
Methods
Close()
Closes the reader if it is still open.
Declaration
public void Close()
Dispose()
Releases any resources associated with the reader.
Declaration
public void Dispose()
Read()
Parses and returns the next row of fields.
Declaration
public List<string> Read()
Returns
Type | Description |
---|---|
List<string> | A list of parsed field strings or |
Rows()
Returns an enumerator that returns the data rows from a CsvReader.
Declaration
public IEnumerable<List<string>> Rows()
Returns
Type | Description |
---|---|
IEnumerable<List<string>> | The next row as a List<T>. |