清除文本文档中的多余分隔符

这是一个DELPHI编写的小程序,对于对付网上众多靠空格和换行加长篇幅的文章。它可以清除多余的空格、换行及TAB。DELPHI7,WINXP编码通过
program pcliptxt;
{$APPTYPE CONSOLE}
uses
  SysUtils,classes;

const
  TTheFmtChar=[#9,#10,#13,#32];
  THeadLine=#13#10#32#32;
var
  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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值