.net - How to read multilines from text file in c# -


I have a text file that contains user records. A user record exists in three files in the text file. Now, according to my requirement, I have to read the first three rows for a user, put it into the process and the database and the next three lines for the other user and so on .. Here is the code that I used to use. Read a single line from the text file.

  if (System.IO.File.Exists (location) == true) {use (streamreader reader = new streamer (location)) { While ((line = reader. Readline ())! = Null {line = Ain. Rim (); }}}  

Please help me to read multi-line, in this case 3 lines from the text file.

Thank you ..

< / Div>

You can do something like this:

  if (System.IO.File.Exists (Place) == true) {var rows = file. Read offline (location); Int username = lines Count () / 3; {Var firstField = line [i * 3] for (int i = 0; i & lt; usersNumber; i ++); Var Secondfield = Line [i * 3 + 1]; Var thirdField = line [i * 3 + 2]; DoStuffs (firstField, secondField, thirdField); } If (Lines number ()> Usend number * 3) // DoSomethingElseFrom (line, index = (usersNumber * 3 + 1)) if additional lines will be skipped; }  

You are reading all the rows of your file, how many users (groups of 3) you count, then for each group that you are retrieving your affiliate information , And in the end you are processing a group of 3 areas related to the same user.


Comments