c# - Text file reader not reading until end of file -
i have following text file use position , length rule substring value of give string.
id b element name element c length position key2 01 pn pnfn user mid nam usr 1 1 2 ....about 60 rows
here how reading the text file , apply position , length value of text file string input.
string input = "aaaaabbbbccccddddgggg......"
**edit** var values = file.readlines("file") .skipwhile(string.isnullorwhitespace).skip(1) .select(l => l.split(new[] {' ', '\t'}, stringsplitoptions.removeemptyentries)); var array1 = offsets.select(split => new { element = split[5], length = int.parse(split[7]), position = int.parse(split[8]) }); foreach (var info in array1) { string substring = input.substring(info.position, info.length); console.writeline("element: '{0}' value: '{1}'", info.element, substring); }
this read 14 rows , breaks loop. there doing wrong? thanks
i used sub string instead of space find exact location:
foreach (var hashtable in item in offsets let element = item.substring(4,2) let length = convert.toint32(item.substring(6, 6)) let position = item.substring(7, 4) select new hashtable { {"element", element}, {"length", length}, {"position", position} })
Comments
Post a Comment