求助:我写的posx()函数有什么问题? ( 积分: 10 )

  • 主题发起人 主题发起人 panminfu
  • 开始时间 开始时间
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;
我用它查找,死循环。。。看了半天,不知错在哪了,请大家看看吧
 

Similar threads

I
回复
0
查看
381
import
I
I
回复
0
查看
430
import
I
I
回复
0
查看
687
import
I
后退
顶部