c# - Reading Text file with Linq with 2 patterns -


i need read text file

myitemname = description @ moreinfo 

now need convert 3 fields in table. using '=' , '@' pattern.

just splitting on = , @ - returns , ienumerable of anonymous class properties interested in:

var items = file.readalllines(filename)                 .skip(1) //skip header                 .where( line => !string.isnullorwhitespace(line))                 .select(line =>                 {                     var columns = line.split('=', '@');                     return new                     {                         itemname = columns[0].trim(),                         description = columns[1].trim(),                         moreinfo = columns[2].trim()                     };                 }); 

this approach require separator tokens used separators exclusively - if occur in of fields, mess , void approach.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -