i want to edit a textfile. if i read a special line (let us say //–begin editing text here–//) then after this line i want to insert several lines but i don’t want to override existing lines. is this possible with delphi? thanks!
sample text:
this
is a file
with text in it
//–begin inserting text here–//
and nothing in between
sample text after edit:
this
is a file
with text in it
//–begin inserting text here–//
now there is something
in between
and nothing in between
There are several ways you can do this.
The simplest version:
You can also use other File IO Commands such as:
To Read a text file:
The to write out what you want..
It should be noted that in reality both of the above methods are actually just rewriting the entire contents of the file.
The
TFileStreamclass allows you manipulate the actual bytes of a file. In general you would need to read until you found the expected text. Then read ahead and cache the rest of the file, as you write out the new ending of the file.