c# - How to remove trailing empty lines in FileHelper -
thought easy, cannot find methods in filehelpengine remove trailing empty lines in text or csv file, causes readfile fail.
if number of empty lines known, example 2, can use in record class:
[ignorelast(2)] public class ...
another option ignore empty lines ignored in place appear
[ignoreemptylines()] public class ...
the last thing can try ignore lines code using inotifyread interface like:
[fixedlengthrecord(fixedmode.allowvariablelength)] [ignoreemptylines] public class ordersfixed :inotifyread { [fieldfixedlength(7)] public int orderid; [fieldfixedlength(8)] public string customerid; [fieldfixedlength(8)] public datetime orderdate; [fieldfixedlength(11)] public decimal freight; public void beforeread(beforereadeventargs e) { if (e.recordline.startswith(" ") || e.recordline.startswith("-")) e.skipthisrecord = true; } public void afterread(afterreadeventargs e) { // want drop records no freight if (freight == 0) e.skipthisrecord = true; } }
Comments
Post a Comment