Remove char from binary

I want to remove the char / string from a binary / text file. If I know the position of the char / line from the file, how do I delete it? Should I read the file (BlockRead), delete the char / line (using Delete (source, startPos, endPos), and then write (BlockWrite) to a new file, or can I delete directly from the specified file?

thanks

+3
source share
2 answers

You can use the TFileStream.CopyFrom method to copy to an unwanted line, go past it, and then copy the rest of the file again. TFileStreams is pretty fast.

Something like this (untested)

aInFile := TFileStream.Create(sInput, fmOpenRead);
try
  aOutFile := TFileStream.Create(sOutput, fmCreate);
  try
    aOutFile.CopyFrom(aInFile, Pos);
    aInFile.Seek(Skip);
    aOutFile.CopyFrom(aInFile, aInfile.Size - Pos - Skip);
  finally
    aOutFile.Free;
  end;
finally
  aInFile.Free;
end;
+12
source

, , , , .

- .

+1

Source: https://habr.com/ru/post/1720244/


All Articles