Add a text at a certain position

Asked

Viewed 1,460 times

0

Hello, I need to add a TEXT at a certain position of a TXT file, if possible using STRING LIST.

I have a TXT and inside this TXT has about 300 lines. And in the middle of it has the following line:

hardware{98828};

I need to add a TEXT before that sentence there, how can I do ? in case it has to identify that there is this TEXT in the TXT file, and add a word before it.

I look forward to any help!

1 answer

2


You can read the file line by line and save in a Stringlist, as you commented and go checking if there is this "string" in this line with Pos(), for example:

int posicao = Pos(textoDesejado, linha);

if(posicao > 0) { } // encontrou o textoDesejado...

if you find it is possible to edit the text using Copy(), for example:

linha = Copy(linha, 1, posicao) + outroTextoAdicionado + Copy(linha, posicao + 1, Length(linha));

And after putting the line in Stringlist... And so on until you finish reading the entire txt file.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.