P
panminfu
Unregistered / Unconfirmed
GUEST, unregistred user!
function posx(sub:string;str:string;ipos:integer;direction:integer;non_case:boolean):integer;
var
sublen,strlen:integer;
j:integer;
begin
sublen:=length(sub);
strlen:=length(str);
if (sublen>=strlen) or (ipos>=strlen) or (ipos+sublen>=strlen) or (ipos<1) then
posx:=-1;
if (direction<>-1) and (direction<>1) then
posx:=-1;
if (bytetype(str,ipos)=mbtrailbyte) then
ipos:=ipos-direction;
if direction=1 then
begin
if non_case then
begin
while ipos+sublen-1<=strlen do
begin
if (bytetype(sub,1)<>mbsinglebyte) and (bytetype(str,ipos)<>mbsinglebyte) then
j:=2
else
j:=1;
if uppercase(sub)=uppercase(copy(str,ipos,sublen)) then
posx:=ipos
else
ipos:=ipos+j;
end;
end
else
begin
while ipos+sublen-1<=strlen do
begin
if (bytetype(sub,1)<>mbsinglebyte) and (bytetype(str,ipos)<>mbsinglebyte) then
j:=2
else
j:=1;
if sub=copy(str,ipos,sublen) then
posx:=ipos
else
ipos:=ipos+j;
end;
end;
end
else //-------往回查找----------
if non_case then
while ipos>=1 do
begin
if (bytetype(sub,1)<>mbsinglebyte) and (bytetype(str,ipos)<>mbsinglebyte) then
j:=-2
else
j:=-1;
if uppercase(sub)=uppercase(copy(str,ipos,sublen)) then
posx:=ipos
else
ipos:=ipos+j;
end
else
while ipos>=1 do
begin
if (bytetype(sub,1)<>mbsinglebyte) and (bytetype(str,ipos)<>mbsinglebyte) then
j:=-2
else
j:=-1;
if sub=copy(str,ipos,sublen) then
posx:=ipos
else
ipos:=ipos+j;
end;
result:=0; //没找到就返回0
end;
我用它查找,死循环。。。看了半天,不知错在哪了,请大家看看吧
var
sublen,strlen:integer;
j:integer;
begin
sublen:=length(sub);
strlen:=length(str);
if (sublen>=strlen) or (ipos>=strlen) or (ipos+sublen>=strlen) or (ipos<1) then
posx:=-1;
if (direction<>-1) and (direction<>1) then
posx:=-1;
if (bytetype(str,ipos)=mbtrailbyte) then
ipos:=ipos-direction;
if direction=1 then
begin
if non_case then
begin
while ipos+sublen-1<=strlen do
begin
if (bytetype(sub,1)<>mbsinglebyte) and (bytetype(str,ipos)<>mbsinglebyte) then
j:=2
else
j:=1;
if uppercase(sub)=uppercase(copy(str,ipos,sublen)) then
posx:=ipos
else
ipos:=ipos+j;
end;
end
else
begin
while ipos+sublen-1<=strlen do
begin
if (bytetype(sub,1)<>mbsinglebyte) and (bytetype(str,ipos)<>mbsinglebyte) then
j:=2
else
j:=1;
if sub=copy(str,ipos,sublen) then
posx:=ipos
else
ipos:=ipos+j;
end;
end;
end
else //-------往回查找----------
if non_case then
while ipos>=1 do
begin
if (bytetype(sub,1)<>mbsinglebyte) and (bytetype(str,ipos)<>mbsinglebyte) then
j:=-2
else
j:=-1;
if uppercase(sub)=uppercase(copy(str,ipos,sublen)) then
posx:=ipos
else
ipos:=ipos+j;
end
else
while ipos>=1 do
begin
if (bytetype(sub,1)<>mbsinglebyte) and (bytetype(str,ipos)<>mbsinglebyte) then
j:=-2
else
j:=-1;
if sub=copy(str,ipos,sublen) then
posx:=ipos
else
ipos:=ipos+j;
end;
result:=0; //没找到就返回0
end;
我用它查找,死循环。。。看了半天,不知错在哪了,请大家看看吧