22222 / csvtextfieldparser Goto Github PK
View Code? Open in Web Editor NEWA simple CSV parser based on Microsoft.VisualBasic.FileIO.TextFieldParser.
License: MIT License
A simple CSV parser based on Microsoft.VisualBasic.FileIO.TextFieldParser.
License: MIT License
Then you should change the property delimiters to either string or even better char.
Hi 222,
I thought this is the only way to reach you :) Just want to thank you for this code snippets. FYI, I have embedded the main .cs files into my project. Feel free to poke around.
https://github.com/rdagumampan/yuniql
Thanks again,
Rodel / Denmark
The assembly available from NuGet is not signed, which is creating a problem when using in a project that is signed
The VB parser has a property LineNumber.
The parser internally has a lineNumber property.
Could it be exposed to make the interface similar to VB Parser please?
i.e.
public long LineNumber{get{return lineNumber;}}
This one from stackoverflow is good:
public static class CsvTextFileFormatter
{
// https://stackoverflow.com/questions/6377454/escaping-tricky-string-to-csv-format
public static string FormatCsvCell(char separator, string cell, bool alwaysQuote = false)
{
bool mustQuote(string cell) => cell.IndexOfAny(new char[] { separator, '"', '\r', '\n' }) > -1;
if (alwaysQuote || mustQuote(cell))
{
StringBuilder sb = new StringBuilder();
sb.Append('\"');
foreach (char nextChar in cell)
{
sb.Append(nextChar);
if (nextChar == '"')
sb.Append('\"');
}
sb.Append('\"');
return sb.ToString();
}
return cell;
}
public static string FormatCsvRow(char separator, IEnumerable<string> cells, bool alwaysQuote = false)
{
return string.Join(separator, values.Select(cell => FormatCsvCell(separator, cell, alwaysQuote)));
}
}
VB parser has default value for TrimWhiteSpace true, while this parser has default value false
Hello
Can you please add workaround for lines like this:
"=HYPERLINK(""http://www.theice.com/products/67445363"",""Coffee "C" Calendar Spread Option"")","4137","KC","KC","","","Coffee","Coffee C","ICUS","IFUS","Coffee C"
"=HYPERLINK(""http://www.theice.com/products/4210003"",""Weekly Coffee "C" Options"")","3731","KCW","KCW","","","Coffee","Coffee C","ICUS","IFUS","Coffee C"
I.e., when there is a quote inside the quote ("Weekly Coffee -->"C"<--- Options")
Currently its considered as malformed
first off thank you for this project, such a life saver seeing that Microsoft left the VB reference by the wayside for core.
it'd be great if you could setup the parameters in the constructor like you can with the Visual Basic method
var categoryParser = new TextFieldParser(category)
{
Delimiters = new[]{ "|" },
HasFieldsEnclosedInQuotes = false,
TrimWhiteSpace = true
};
also would be great if the constructor would accept a string and not a stringreader
string s = "a,b,\r\n";
When using the VB parser, the ReadFields() method results in 2 fields
When using this parser, the ReadFields() method results in 3 fields
string s = "a,b\r\n";
functions as expected
string s = "a,b,";
When using the VB parser, the ReadFields() method results in 3 fields
When using this parser, the ReadFields() method results in 3 fields
this results in the correct behaviour that is specially coded in ReadFields() line 111, "if the last char is the delimiter, then we need to add an extra empty field"
Getting the error: is too long, or a component of the specified path is too long.
When parsing a CSV with 100,000 records and 30 columns.
Can you tell me what the limit on the string is?
`
private CsvMalformedLineException CreateMalformedLineException(string message, string errorLine, long errorLineNumber)
{
ErrorLine = errorLine;
ErrorLineNumber = errorLineNumber;
return new CsvMalformedLineException(
message: message,
lineNumber: errorLineNumber
);
}
`
Curious, is ErrorLine forgotten here when creating CsvMalformedLineException? Because as I can see you pass only message & lineNumber.
More of a question than an issue: as function ParseCsvWithHeaderIgnoreErrors returns an IEnumerable<IDictionary<string, string>> collection, is the order of the items in the collection guaranteed in subsequent iterations? In other words, is the original (.csv) order of the lines preserved when iterating through the collection using foreach? In my tests it would seem so, yet discussions about IEnumerable suggest this is not the case (e.g., here).
Same like in TextFieldParser
@22222
https://nofile.io/f/oKHADXvTwwS/ICEProductCodeFile.csv - curious, why this file cannot be parsed? It fails with this error:
Line 2638 cannot be parsed because of trailing characters after an end quote.
and this:
Line 318 cannot be parsed because of trailing characters after an end quote.
Works fine with original TextFieldParser.
Stacktrace:
[16:30:48.248] [0.000] at ICEProductCode.Helper.ProductCodeCache.ParseProductCodeContent(String dataContent) in ProductCodeCache.cs: 121
[16:30:48.248] [0.000] at CsvTextFieldParser.ReadFields() in CsvTextFieldParser.cs: 121
[16:30:48.248] [0.000] at CsvTextFieldParser.ParseField(String& line, Int32 startIndex, Int32& nextStartIndex) in CsvTextFieldParser.cs: 138
[16:30:48.248] [0.000] at CsvTextFieldParser.ParseFieldAfterOpeningQuote(String& line, Int32 startIndex, Int32& nextStartIndex) in CsvTextFieldParser.cs: 290
Used in this context:
https://pastebin.com/7YrPwkd0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.