function TForm1.CompStr(FormerStr1, FormerStr2: string): string;
var
FinalInt : integer;
same : boolean;
I : integer;
begin
//去掉空格并转为WideString
FormerStr1 := WideString(Trim(FormerStr1));
FormerStr2 := WideString(Trim(FormerStr2));
//找到最后出现第一个字符串的位置
for I := 1 to Length(FormerStr1) do
if FormerStr1 = FormerStr2[1] then
FinalInt := I;
//检查字符串是否不相同
same := false;
for I := FinalInt to Length(FormerStr1) do
if FormerStr1 <> FormerStr2[i - FinalInt + 1] then
same := true;
if (Length(FormerStr1) - FinalInt <= 2) or same then
result := FormerStr1 + FormerStr2
else
result := copy(FormerStr1, 1, FinalInt - 1) + FormerStr2;
end;
今天非常难得有清闲,就写好给你了!