这是一个DELPHI编写的小程序,对于对付网上众多靠空格和换行加长篇幅的文章。它可以清除多余的空格、换行及TAB。DELPHI7,WINXP编码通过
program pcliptxt;
{$APPTYPE CONSOLE}
uses
SysUtils,classes;
SysUtils,classes;
const
TTheFmtChar=[#9,#10,#13,#32];
THeadLine=#13#10#32#32;
var
fCount:integer;
fHasChar,fHeadLine:boolean;
msSrc:TMemoryStream;
i:integer;
fCount:integer;
fHasChar,fHeadLine:boolean;
msSrc:TMemoryStream;
i:integer;
begin
{ TODO -oUser -cConsole Main : Insert code here }
if ParamCount<1 then begin
writeln('Examples:cliptxt TextFilename');
exit;
end;
if not FileExists(ParamStr(1)) then begin
writeln('The file:',ParamStr(1),'not found!');
exit;
end;
fHeadLine:=false; fHasChar:=false;
mssrc:=TMemoryStream.Create;
try
mssrc.LoadFromFile(ParamStr(1));
i:=0;fcount:=0;
while i<=mssrc.size-1 do begin
if (pchar(mssrc.Memory)[i] in TTheFmtChar) then begin
if not fHasChar then
fHasChar:=true
else begin
inc(i);
inc(fcount);
end;
if pchar(mssrc.memory)[i] in [#10,#13] then
fHeadLine:=true;
end
else begin
if fHeadLine then begin
write(THeadLine);
fHeadLine:=false;
end
else begin
if (fHasChar) and (0<fCount) then
dec(i);
end;
fHasChar:=false;
Write(pchar(mssrc.memory)[i]);
inc(i);
end;
end;
finally
mssrc.Free;
end;
end.