ka1a
asked on
cleanup a ASCII file
Hello everyone,
I need to cleanup a ASCII file. With cleanup I mean remove certain characters (#13, #10, ...). At this moment I open the file as ‘file of bytes’. I create a another ‘file of bytes’. I read a character. If the character is in the list I give up, the character is written to the new file, else it will not be written. And so on to the end of the file. It works, but it is very slow (most files are around 2 Mb).
Is there another (faster) way to do this. The cleanup must be correct. So the procedure must be 100 % reliable.
All suggestions are welcome.
Thanks in advance.
Dirk.
PS sorry for my poor english.
I need to cleanup a ASCII file. With cleanup I mean remove certain characters (#13, #10, ...). At this moment I open the file as ‘file of bytes’. I create a another ‘file of bytes’. I read a character. If the character is in the list I give up, the character is written to the new file, else it will not be written. And so on to the end of the file. It works, but it is very slow (most files are around 2 Mb).
Is there another (faster) way to do this. The cleanup must be correct. So the procedure must be 100 % reliable.
All suggestions are welcome.
Thanks in advance.
Dirk.
PS sorry for my poor english.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Of course, you can set buffersize as you need (but <=64k).
:-)
Jo.
:-)
Jo.
BufferR,BufferW : array[0..$7FFF] of byte;
OldFile,NewFile : File;
.....
AssignFile(OldFile,'oldfil
Reset(OldFile,1);
AssignFile(NewFile,'newfil
Rewrite(NewFile,1);
repeat
BlockRead(OldFile,BufferR,
if amtread > 0 then
begin
amttowrite := 0;
for i:=0 to amtread do
if not(BufferR[i] in [#10,#13..whatever]) then
begin
BufferW[amttowrite] := BufferR[i];
inc(amttowrite);
end;
Blockrite(NewFile,BufferW,
end;
until amtread = 0;
CloseFile(OldFile);
CloseFile(NewFIle);