Skip to content

quoted text errors out #210

Closed Answered by MarkPflug
BabakRabie asked this question in Q&A
Aug 8, 2023 · 3 comments · 3 replies
Discussion options

You must be logged in to vote

Your file is a non-standard format and needs special configuration.

The following code should do what you want:

using Sylvan.Data;
using Sylvan.Data.Csv;
using System.Data.Common;

var filename = "MyFileName.csv";

// example data
var data = "a|b|c\nx|\"y\" y|z\n";
var opts =
    new CsvDataReaderOptions {
        CsvStyle = CsvStyle.Escaped,
        Escape = '\0',
        Quote = '\0',
    };

var r = CsvDataReader.Create(new StringReader(data), opts);

// create a new data reader with the filename and row number attached.
DbDataReader r2 = r.WithColumns(
    new CustomDataColumn<string>("Filename", _ => filename),
    new CustomDataColumn<int>("Row", _ => r.RowNumber)
    );

var wo = new

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@BabakRabie
Comment options

@MarkPflug
Comment options

Answer selected by BabakRabie
Comment options

You must be logged in to vote
1 reply
@MarkPflug
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants