Code Monkey home page Code Monkey logo

csvtextfieldparser's Issues

Thanks!

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

Assembly signing

The assembly available from NuGet is not signed, which is creating a problem when using in a project that is signed

Feature Request: LineNumber property

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;}}

Suggestion: Include a CsvTextFileFormatter as well?

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)));
	}
}

Issue with line parsing

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

add some constructor parameters

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

Parsing difference between VB parser and this parser

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"

No errorLine is shown when thrown MalformedException

`

   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.

Item order in subsequent iterations?

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).

Cannot parse some csv file

@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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.