I did it like this. And files of 500 megabytes in size do not process - lack of memory):

procedure TForm1.Button1Click(Sender: TObject); var t:TStringList; s: string; k,n,i: integer; begin n:=strtoint(Edit1.Text);//удалить в начале k:=strtoint(Edit2.Text);//удалить в конце t:=TStringList.Create; t.LoadFromFile('1.txt');//файл в папке с программой for i:=0 to t.Count-1 do begin s:=t[i]; if k>=length(s) then s:='' else delete(s,length(s)-k+1,k); if n>=length(s) then s:='' else delete(s,1,n); t[i]:=s; end; t.SaveToFile('2.txt'); t.Free; ShowMessage('Файл 1.txt преобразован и записан в файл 2.txt') end; 

How to remake through:

AsssignFile, Reset / Rewrite, CloseFile

That is, read in rows and not load into memory.

>>> I do this (What is my mistake?): <<<

 procedure TForm2.Button1Click(Sender: TObject); var f1,f2:TextFile; s:string; k,n,i: integer; begin if OpenDialog1.Execute then begin AssignFile(f1,OpenDialog1.FileName); AssignFile(f2,ExtractFileDir(OpenDialog1.FileName)+'\out.txt'); {$i-} Reset(f1); Rewrite(f2); begin s:=f1[i]; if k>=length(s) then s:='' else delete(s,length(s)-k+1,k); if n>=length(s) then s:='' else delete(s,1,n); f2[i]:=s; end; CloseFile(f1); CloseFile(f2); end; end; end. 
  • 2
    Tatyana, we are following your actions with interest at StackOverflow, rejoicing at your successes, experiencing failures. Recently you have asked half a dozen questions, the answer to which is absolutely the same. Here is one of them.stackoverflow.com/questions/790226 with your own answer. What's the matter with you, Tatyana? - Igor
  • First of all thanks from the heart. Everything is fine with me, I have already gone through the training. Thanks to universal criticism. In this question, I have been fighting with the code for two hours already. And so far from 10 attempts it is impossible to remake. - Tatyana
  • one
    Add your code with line reading / writing to the question and help you find the error. - Igor
  • One minute. I'll do it now. - Tatiana
  • Igor 9, Added a code to the main question. As you said. - Tatyana

2 answers 2

 while not EOF(f1) do // вместо for ... в случае с TStringList begin ReadLn(f1, s); // вместо s:=f1[i]; ... WriteLn(f2, s); // вместо f2[i]:=s; end; 

... cleans completely. What else could be wrong

Another mistake is that you do not assign the value n . In this uninitialized local variable is garbage corresponding to some large integer. Therefore, the condition n>=length(s) always true, and the string is always cleared.

Variable k Your code also does not assign any value.

  • So did, works, but does not cut the file? A cleans completely. What else could be wrong? Thank you in advance. - Tatyana
  • Assigned condition n: = strtoint (Edit1.Text); // delete at the beginning k: = strtoint (Edit2.Text); // delete at the end. And now it cuts, but leaves only the first line and removes the remaining lines. What is the mistake here? - Tatyana
  • one
    @ Tatyana Added a while in response. - Igor
  • one
    @ Tatyana This resource is considered to be a good form to "accept" the correct answer to a question by clicking on the checkmark sign to the left of the answer. - Igor
  • one
    @ Tatyana On health. Successes! - Igor

Thanks to user Igor it turned out. Answer to the question:

 n:=strtoint(Edit1.Text); //удалить в начале k:=strtoint(Edit2.Text); //удалить в конце AssignFile(f1,OpenDialog1.FileName); AssignFile(f2,ExtractFileDir(OpenDialog1.FileName)+'\out.txt'); {$i-} Reset(f1); Rewrite(f2); while not Eof(f1) do begin ReadLn(f1, s); if k>=length(s) then s:='2' else delete(s,length(s)-k+1,k); if n>=length(s) then s:='2' else delete(s,1,n); WriteLn(f2, s); end; 
  • 3
    {$i-} better remove. It is better to immediately find out about the errors that occur as an exception. - Kromster