Add text in a certain position

0

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

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

hardware{98828};

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

I look forward to any help!

    
asked by anonymous 03.06.2016 / 14:14

1 answer

2

You can go reading the file line by line and saving it to a StringList, as you commented and go check if there is this string in this line with Pos (), for example:

int posicao = Pos(textoDesejado, linha);

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

If find, you can 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 the StringList ... And so on until you finish reading the whole txt file.

    
07.06.2016 / 10:02