DELPHI的通配符比较

                           DELPHI的通配符比较
                  
              作者:李均宇  email:     e271828@163.net或者MSSQLserver2000@163.com或者OKMYdelphi@163.net
 
    DELPHI的功能比VB强是公认的,但在一些小事小节上却有时比不上VB方便,例如VB中有SENDKEY()可以很方便地模拟键盘按键,但在DELPHI中就比较繁些.又如VB中有LIKE来轻易实现通配符的比较,但在DELPHI中却找不到,为此在处于自由状态下的我尚有心情时便自已动手来作一个自定义的函数来实现这个功能,以防应急时无心情再作这种小程序.这种小程序束之高阁无用,不如拿出来让它发出几分光和热.
    程序的算法先在子串的末尾加上‘?*’,再读取子串,查找子串中的通配符之间的字符,亦即子串中的子串,然后在源串中依次查找是否含有子串中的子串,不过实现起来还是十分费些周折.
function   isABClikeAX(abc,ax:string):boolean;   //abc是源串,ax是子串
var
abcstart,axstart,abclength,axlength:integer;
endpartabc,endpartax,subax:string;
temp,abcwww,axwww:integer;
begin //aaa
temp:=0;
abcstart:=1;
axstart:=1;
axwww:=1;
abcwww:=1;
abclength:=length(abc);
axlength:=length(ax);
isabclikeax:=true;
while  axstart<=axlength  do
  begin//bbb
    if ax[axstart]='?'  then
    begin
    inc(axstart);
    inc(abcstart);
    if  abcstart> abclength then
    begin
     isabclikeax:=false;
    break;
    end;
    continue;
    end;
    if  ax[axstart]='*'  then
    begin
    inc(axstart);
    temp:=1;
    axwww:=axstart;
    abcwww:=abcstart;
    continue;
    end;
    if not(ax[axstart]  in  ['?','*'] ) then
    begin//ccc
    endpartax:=copy(ax,axstart,axlength-axstart+1)+'?*';

subax:=copy(endpartax,1,min(pos('?',endpartax),pos('*',endpartax))-1);
    axstart:=axstart+min(pos('?',endpartax),pos('*',endpartax))-1;
    endpartabc:=copy(abc,abcstart,abclength-abcstart+1);
    if ((pos(subax,endpartabc)<>0) and (temp=1 )) or ((pos(subax,endpartabc)=1) and (temp=0)) then
    begin  //ddd
    if temp=1  then      temp:=0;
    abcstart:=abcstart+(pos(subax,endpartabc)+length(subax)-1) ;
    // axstart:=axstart+min(pos('?',endpartax),pos('*',endpartax))-1;
    end   //ddd
    else   //ddd
    begin  //ddd
      if temp=0  then
      begin
      axstart:=axwww;
      abcwww:=abcwww+1;
      abcstart:=abcwww;
      temp:=1;
      continue;
      end;
    isabclikeax:=false;
    break;
    end;  //ddd
    end;//ccc
  end;//bbb
end;//aaa

FUNCTION islike(abc,ax:string):boolean;
begin
islike:=isABClikeAX(abc,ax);
end;
FUNCTION widecard(abc,ax:string):boolean;
begin
widecard:=isABClikeAX(abc,ax);
end;

注意USES MATH,因为用到MIN(),也可以用IF语句来代替MIN(),但不够明白.


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值