0

I have a text file that each line of it ,is a record of data with a specific structure. I want to read it Line by Line, in a specific Line for example in Line 1000 Change a data Like:

 sara , 1991 , Zakizadeh , Student , Tehran
 Eli , 2005 , Lord , teacher , London
 Elias , 1875 , Lion , farmer , Berlin

Change to:

 sara , 1991 , Zakizadeh , Student , Tehran
 Eli , 2005 , Lord , teacher , London
 Elias , 1875 , Star, farmer , Berlin  ****

I can find the number of line and and can change the data and update the same line, but there are some problems:

  • maybe the amount of characters in a line after update be more than a line and it be continued in another line!
  • if I want to prevent top problem , I can to put limitation for each data for example Name : 20 Char , Birth date: 4 char ,.... but if its data be less than this amount it can make Redundancy in such a large file about more than 6000 lines.

What is your solution?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Sara Zakizadeh
  • 137
  • 1
  • 8

2 Answers2

0

I think you should check that what is EOL char in your text file, in pre-elementary C# course, we worked with some sequence escape chars and \r \n were chars for new line,

in fact, there is End Of Line char that define next char is in new line,

you can use ReadLine() and see how many lines is returned, if this count is equal to real text file's line count, go on and do your work,

  • thank you but I don't have any problem in Reading a Line! my problem is when I update my new Line , maybe the number of characters be more than a line! it goes to the second lines ! – Sara Zakizadeh Jan 26 '15 at 05:49