GetRecords<dynamic> Not escaping quotes while GetField() seems to do so? #1845
-
Hi there! I'm trying to read in a CSV file using GetRecords, but it doesn't seem to escape quotes while GetField() seems to do so. Here's what my CSV looks like:
Here's the code I'm using to read by hand:
When reading through my CSV using GetRecords, I get Currently the API I'm using doesn't like Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I'm not getting that result when reading by hand. void Main()
{
var s = new StringBuilder();
s.Append("name,id\r\n");
s.Append("\"\"\"Hello\"\", World\", 123\r\n");
s.Append("Bob,678\r\n");
var records = new List<Foo>();
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
};
using (var reader = new StringReader(s.ToString()))
using (var csv = new CsvReader(reader, config))
{
csv.Read();
csv.ReadHeader();
while (csv.Read())
{
var record = new Foo
{
Id = csv.GetField<int>("id"),
Name = csv.GetField("name"),
};
records.Add(record);
}
records.Dump();
}
}
private class Foo
{
public int Id { get; set; }
public string Name { get; set; }
} I could have to crate a way to get the raw field in the parser to do what you want to do. |
Beta Was this translation helpful? Give feedback.
I'm not getting that result when reading by hand.