Delphi 下的通配符查找函数


本文整理自网络,侵删。

 

//Delphi 下的通配符查找函数

Function IsLike(ax, abc: String): Boolean; //ax是子串,abc是源串

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;

  ax:=LowerCase(ax);

  abc:=LowerCase(abc);

  abclength := Length(abc);

  axlength := Length(ax);

  result := True;

  While axstart <= axlength Do Begin //bbb

    If ax[axstart] = '?' Then Begin

      inc(axstart);

      inc(abcstart);

      If abcstart > abclength+1 Then Begin

        result := 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) + '?*';

      If Pos('?', endpartax) < Pos('*', endpartax) Then Begin

        subax := Copy(endpartax, 1, Pos('?', endpartax) - 1);

        axstart := axstart + Pos('?', endpartax) - 1;

      End

      Else Begin

        subax := Copy(endpartax, 1, Pos('*', endpartax) - 1);

        axstart := axstart + Pos('*', endpartax) - 1;

      End;

      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);

      End

      Else  Begin //ddd

        If temp = 0 Then Begin

          axstart := axwww;

          abcwww := abcwww + 1;

          abcstart := abcwww;

          temp := 1;

          Continue;

        End;

        result := false;

        Break;

      End; //ddd

    End; //ccc

  End; //bbb

End; //aaa

相关阅读 >>

Delphi学习sql语句 - insert、update、delete

Delphi 如何获取桌面图标方法

Delphi 链接文件名合并

Delphi firemonkey 绘图

Delphi 判断字符串是否包含数字

Delphi ios 保持设备开机状态

Delphi的webbrowser改造,对网页中alter等对话框的改造方法

Delphi 减小程序的尺寸(关闭rtti反射机制)

Delphi 获取硬盘序列号(ide,sata,scsi)

Delphi路径分割符处理相关函数

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...