Replies: 5 comments 2 replies
-
If you set csv.Configuration.BadDataFound = null; it will work as you expect. |
Beta Was this translation helpful? Give feedback.
-
void Main()
{
var s = new StringBuilder();
s.AppendLine("SKU,LENGTH,WIDTH,HEIGHT");
s.AppendLine("3T-ARX-100,7,4.2,2.1");
s.AppendLine("WT-TSC-26\"-K,16,14,5.3");
using (var reader = new StringReader(s.ToString()))
using (var csv = new CsvParser(reader))
{
csv.Configuration.BadDataFound = null;
while (true)
{
var value = csv.Read();
if (value == null)
{
break;
}
value.Dump();
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Why is this considered 'bad data'? The quote is embedded in the middle of the record, not at the start and end of it? |
Beta Was this translation helpful? Give feedback.
-
If a field contains a quote or a comma, it's supposed to be wrapped in quotes, and the quote escaped. https://tools.ietf.org/html/rfc4180#page-2
|
Beta Was this translation helpful? Give feedback.
-
I'm also encountering the same issue. In my case there is a text field that a user can manually input a description into and quite often they are putting things in quotes, example is below. 1,2,3,Tune!FM.net "Feeder Ninja" April - May,RandomDate,RandomNumber The solution you gave seems to be to set BadDataFound to null, however, when I actually encounter a cell that contains bad data, I wont know about it or have any way to handle it.
|
Beta Was this translation helpful? Give feedback.
-
This file used to parse correctly in older versions of CsvHelper, and now it barfs saying there is bad data. But this is not bad data at all. Having a quote character in the middle of a cell should not cause the parser to barf. The quotes in a cell should only be parsed if they are immediately following the delimiter character and then the end one should be expected to be at the end. It should be possible to also have a single quote in the middle of the quoted section as well.
Now you could argue this is malformed data, but it is very common to see this and it used to parse correctly. It also loads just fine in Excel.
Beta Was this translation helpful? Give feedback.
All reactions