CSV with \ n \ r in lines - how to determine the end of a line? `

I have a very large CSV with 244 columns and 4000 rows. There are many \ n \ r, so when I try to split it into this (to find the end of the line) I get about 9000 lines instead of the 4000 I want.

So how do you determine which \ n \ r is in the text, or maybe at the end of a cell, and which is the final end of the line?

+3


source to share


2 answers


When a CSV file has data in a column that is \ n, \ r, or, quotes are usually placed around these values. To edit the CSV correctly, I would recommend the already existing parsers. See this answer for an example.



If you really want to be yourself, you need to write a simple state machine that reads data on individual columns. You must follow the evacuation rules when reading the column. This is the only way you could distinguish between line endings in data and line endings that highlight lines.

+1


source


try using Environment.NewLine

for splitting instead of \ n \ r



string path = yourfilepath;
string csv = System.IO.File.ReadAllText(path);
List<string> rows = csv.Split(new string[] {Environment.NewLine }, System.StringSplitOptions.RemoveEmptyEntries).ToList();

      

0


source







All Articles