We often replace unnecessary characters in a file with another “good” character.
Interface:
procedure cleanfileASCII2(vfilename: string; vgood: integer; voutfilename: string);
To replace all unacceptable spaces that we could call cleanfileASCII2 (original.txt, 32, cleaned.txt)
The problem is that it takes quite a while. Here's a better way to do this than shown?
procedure cleanfileASCII2(vfilename: string; vgood: integer; voutfilename:
string);
var
F1, F2: file of char;
Ch: Char;
tempfilename: string;
i,n,dex: integer;
begin
AssignFile(F1, vfilename);
Reset(F1);
AssignFile(F2,voutfilename);
Rewrite(F2);
while not Eof(F1) do
begin
Read(F1, Ch);
n:=ord(ch);
if ((n<32)or(n>127))and (not(n in [10,13])) then
begin
if vgood<> -1 then
begin
ch:=chr(vgood);
Write(F2, Ch);
end
end
else
Write(F2, Ch);
end;
CloseFile(F2);
CloseFile(F1);
end;
Shane source
share