比如:
IP1:=111.222.333.444
IP2:=1?1.222.333.444
IP3:=111.*.333.444
怎么比较才能让它们相等?
来自:
011101,
时间:2004-8-1 22:39:14,
ID:2742935
有几个?就跳过几个字符。
*号不知怎么办?
来自:
易名烦,
时间:2004-8-1 22:51:31,
ID:2742949
*就跳过.和.之间的东东.
来自:
sh_wkl,
时间:2004-8-1 23:17:54,
ID:2742978
我想,只能自已定义函数处理,如下:
function ipcheck(ip1:string;ip2:string):boolean;
var
s1,s2 :array[1..4] of string;
i,n:integer;
begin
n:=1;
while pos('.',ip1)<>0 do
begin
s1[n]:=format('%-3s',[copy(ip1,1,pos('.',ip1)-1)]);
delete(ip1,1,pos('.',ip1));
n:=n+1;
end;
s1[n]:=format('%-3s',[ip1]);
n:=1;
while pos('.',ip2)<>0 do
begin
s2[n]:=format('%-3s',[copy(ip2,1,pos('.',ip2)-1)]);
delete(ip2,1,pos('.',ip2));
n:=n+1;
end;
s2[n]:=format('%-3s',[ip2]);
result:=true;
for n:=1 to 4 do
begin
for i:=1 to 3 do
begin
if (s1[n][i]='*') or (s2[n][i]='*') then
break;
if (s1[n][i]='?') or (s2[n][i]='?') then
continue;
if s1[n][i]<>s2[n][i] then
begin
result:=false;
exit;
end;
end;
end ;
end;
以上函数可实现你的题目要求,调用ipcheck(ip1,ip2) 返回true为相等,false不等
不足:是否符合ip规则你可在别的地方加校验。
来自:
fffddd,
时间:2004-8-2 10:03:23,
ID:2743399
谢谢三位帮助。
|