您的位置:首页 > 其它

功能:查找两个字符串有没有相同的部分

2013-07-04 14:52 411 查看
function SearchInStrings(const Str1,Str2 : string) : Boolean;

{ ----功能:查找两个字符串有没有相同的部分----- }

var

S1,S2 : string;

I : integer;

Found : boolean;

begin

S1 := Str1;

S2 := Str2;

Found := false;

for I := 1 to Length(S1) do //先找到第一个相同的字符

if (Pos(S1[I], S2)>0) then

begin

Found := true;

Break;

end;

if Found then

begin

S2 := Copy(S2, Pos(S1[I],S2), MaxInt);

S1 := Copy(S1, I, MaxInt);

for I := 1 to Math.Min(Length(S1),Length(S2)) do

if (S1[I] <> S2[I]) then break;

result := True;//Copy(S1, 1, I-1);//相同的内容

end else Result:=False;// := '没找到任何相同的内容';

end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: