question

PolachanPaily-6650 avatar image
0 Votes"
PolachanPaily-6650 asked karenpayneoregon commented

Cannot parse the data from CSV file if there is an enter key pressed between two words in same cell

I am trying to parse the csv file using the following code
string[] EachColumnData = null;
EachColumnData = line.Replace("\",\"", "|").Replace(",,", "||").Replace("\"", "").Split('|');


But it doesnot work,if there is an enter key pressed in between two words of a column value, it would be splitted as new row . I have attached my sample csv format herewith. How can I fix my code to accept the data as a single record even if there is space or enter inside a column value.
201969-capture.png


dotnet-csharp
capture.png (39.9 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you want help, add a text file which can reproduce this issue. Have at least two problem lines and at least two good lines. Using a image is good for visuals but not to recommend a solution.

0 Votes 0 ·

[202043-samplecsvtestfile.txt][1]

I have attached Text file also ,
[1]: /answers/storage/attachments/202043-samplecsvtestfile.txt

0 Votes 0 ·

After reviewing the lines I would say the "z followed by a return is a one-off and not worth fixing in code. Instead read each line without splitting, check that the first character is 0-9 and if not flag it for manual processing.

Also it appears you made an effort to fix other issues (at least I see it that way), seems that you need to set the format and whomever is providing the file needs to adhere to the format or be rejected.

0 Votes 0 ·

0 Answers