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
Post a Comment