vb.net - Read Csv file with LineFeeds within its fields -
i have code read csv file :
dim strlinevalue string using sr streamreader = file.opentext("filepath") strlinevalue = sr.readline while strlinevalue isnot nothing strlinevalue = sr.readline n += 1 loop end using
my problem come across csv file lines this:
"text1 lf lf text2","text3",text4,text5, , , , ,lf "text6 lf lf text8","text9",text10,text11, , , , ,lf
where lf line feed.
so wrong
text1 text2 text3 text4 text5 text6 text8 text9 text10 text11
any ideas how can overcome wrong behaviour of code in type of files
ps. 1.if open csv file in excel recognises lines , have multiline first cell
2. thinking maybe first 2 lf lf , lf have in end of each line lf , cr how can see difference (i opened csv file in word see characters)
you have fields enclosed in double-quotes - "
. in csv files, indicates you're supposed take whole field , not parse it.
this easy microsoft.visualbasic.fielio.textfieldparser class. here's example:
imports microsoft.visualbasic.fileio dim parser textfieldparser = new textfieldparser("testfile.txt") parser.delimiters = new string() {","} parser.hasfieldsenclosedinquotes = true while not parser.endofdata dim fields string() = parser.readfields() end while
this preserve line feeds in quoted fields:
"text1 lf lf text2" "text3" "text"4 "text5" blank blank blank blank blank
Comments
Post a Comment