正在阅读:Delphi学习:2个不错的通配符比较函数Delphi学习:2个不错的通配符比较函数

2004-09-13 14:41 出处:CSDN 作者:Stanley_Xu 责任编辑:linjixiong


  // ===========================
  // Function 2
  // ===========================

  function _MatchPattern(aPattern, aSource: PChar): Boolean;
  begin
  Result := True;
  while (True) do
  begin
  case aPattern[0] of
  #0 : begin
  //End of pattern reached.
  Result := (aSource[0] = #0); //TRUE if end of aSource.
  Exit;
  end;

  '*': begin //Match zero or more occurances of any char.
  if (aPattern[1] = #0) then
  begin
  //Match any number of trailing chars.
  Result := True;
  Exit;
  end else
  Inc(aPattern);

  while (aSource[0] <> #0) do
  begin
  //Try to match any substring of aSource.
  if (_MatchPattern(aSource, aPattern)) then
  begin
  Result := True;
  Exit;
  end;

  //Continue testing next char...
  Inc(aSource);
  end;
  end;

  '?': begin //Match any one char.
  if (aSource[0] = #0) then
  begin
  Result := False;
  Exit;
  end;

 


察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:

键盘也能翻页,试试“← →”键

相关文章

关注我们

最新资讯离线随时看 聊天吐槽赢奖品