Delphi学习:2个不错的通配符比较函数
添加时间: 2006-2-25 5:41:25 作者: Delphi教程 阅读次数:66 来源: http://www.d9soft.com
近日在和朋友讨论 MaskMatch 时偶得2个不错的算法。
函数1 只支持'*','?'模糊匹配。速度比采用递归算法的快近2倍,比TMask方法快很多。
函数2 完全支持正规表达式。速度于之前的相同。(不会正规表达式的朋友慎用)
| // =========================== // Function 1 // =========================== // Check if the string can match the wildcard. It can be used for unicode strings as well! |
|
Break; repeat // mit vorangegangenem "*" |
|
// =========================== function _MatchPattern(aPattern, aSource: PChar): Boolean; '*': begin //Match zero or more occurances of any char. while (aSource[0] <> #0) do //Continue testing next char... '?': begin //Match any one char. |
|
//Continue testing next char... '[': begin //Match given set of chars. if (aPattern[1] = '^') then |
|
Inc(aPattern); if (Result) then |
|
while (aPattern[0] <> ']') and (aPattern[0] <> #0) do Inc(aPattern); else begin //Match given single char. //Continue testing next char... function MatchPattern(const aPattern, aSource: string): Boolean; |
上一篇文章: Delphi控制Excel的重要属性和方法 下一篇文章: 字符串分割扩展 SplitEx
相关文章:

