Gordon Waters wrote:
> I am trying to format a series of text files and combined them in to one
> large file.
>
> My issue is that my input text files are generated by an external
> system, and this is putting 4 blank lines through out the text file,
> what I am trying to do is to remove these 4 blank lines.(and only the 4
> blank lines) from the files.
>
> I am currently reading the input files from disk, and appending them to
> a memo, I then save this memo back to disk with a new name.
>
> So what I am asking is what is a easy way to detect 4 x CR LF in a row
> and skip appending these to my memo.
Take a list of files, read their contents, turn four consecutive line
breaks into just one, and write the new contents to the new file.
procedure AppendFiles(const InNames: TStrings; const OutName: TFileName);
var
i: Integer;
InFile, OutFile: TStream;
InContents, OutContents: string;
begin
OutFile := TFileStream.Create(OutName, fmCreate);
try
for i := 0 to Pred(InNames.Count) do begin
InFile := TFileStream.Create(InNames[i], fmOpenRead or
fmShareDenyWrite);
try
SetLength(InContents, InFile.Size);
if Length(InContents) > 0 then
InFile.ReadBuffer(InContents[1], Length(InContents));
OutContents := StringReplace(InContents,
#13#10#13#10#13#10#13#10, #13#10, [rfReplaceAll]);
if Length(OutContents) > 0 then
OutFile.WriteBuffer(OutContents[1], Length(OutContents));
finally
InFree.Free;
end;
end;
finally
OutFile.Free;
end;
end;
--
Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi