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;
我一执行就陷入死循环,那里的问题?大家看看~0~
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;
我一执行就陷入死循环,那里的问题?大家看看~0~