Ignoring last lines in CSV using Filehelpers if they aren't input

大憨熊 提交于 2019-12-08 08:35:06

问题


I built a program using FileHelpers to parse CSV files and it works wonders, except I'm running into an issue. Some of the files - but not all - have a number of extra lines in the end with information that does not pertain to actual fields.

like so

...
31,4104019, ,,1043,,,0,,Ventas Total Credito,1,1,277.98,0,0,0,0,21.5040000000,V,
31, ,11212302,,1043,,,0,,Ventas Total Credito,1,1,33.28,0,0,0,0,21.5040000000,V,
31, ,11212307,,1043,,,0,,Ventas Total Credito,1,1,277.98,0,0,0,0,21.5040000000,V,

;Importado="01/11/2013"
 //blank line here too

I know FileHelpers has the

[IgnoreLast(3)] 
public class whatever...

option, but as only some of the files have those extra 3 lines, Using this for all could result in the last 3 records being ignored for some files.

Is there any way to tell it when to ignore a line? Or should I read the file separately first and remove those lines myself?


回答1:


You can use the BeforeReadRecord event or implement in the record INotifyRead interface that is more simple.

In both cases use e.SkipThisRecord = true; in the cases that you need to discard



来源:https://stackoverflow.com/questions/19933439/ignoring-last-lines-in-csv-using-filehelpers-if-they-arent-input

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!