"Jon" <ro*******@mainstreams.com> schrieb
I am trying to accomplish the following with a text file...
1 open the file
2 loop through it line by line
3 if need be, modify the current line
4 replace the old line in the file with the newly modified line 5
close the file
I know how to do 1,2,3 and 5, but I'm not having any luck writing
the modified line back to the file (preferably at the same position)
and removing the old line.
Can anyone shed some light on that portion of it? Thanks
You can not modify a line unless it's length didn't change.
If the length has changed, read the rest of the file after the line to be
modified, set the Position property of the stream, write the new line and
write the rest of the file.
If the length did not change, set the Position property and write the new
line.
Take into account that, depending on the encoding of the file, the resulting
number of bytes in the file might change although the number of chars did
not change.
Armin