var
s1,s2,s3:string;
i:integer;
begin
s1 := edit1.Text; s2 := edit2.Text; s3 := '';
if length(s1) <> length(s2) then
showmessage('两个串不等长!')
else
begin
for i := 1 to length(s1) do
begin
if pos(s2[i],s1)=0 then s3 := s3 + s2[i];
if pos(s1[i],s2)=0 then s3 := s3 + s1[i];
end;
edit3.Text := '共有'+inttostr(length(s3))+'个字符不同,他们是:'+s3;
end;
end;
var
str1,str2: String;
StrLenth,i,Count: Integer;
begin
str1 :='fdfasdfdasf';
str2 :='345wgsdgreg';
StrLenth := Length(str1);
i := StrLenth;
j := i;
for i := 1 to StrLenth do
begin
for j := 1 to StrLenth do
begin
If Copy(str1,i,1) = Copy(str2,j,1) then Break
else If j = StrLenth then Count := Count +1;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s1, s2, s3: WideString;
i: integer;
begin
s1:='我是一个好人啊lilor';
s2:='我是一个坏人吗lilor';
for i:=1 to length(s1) do
begin
if (pos(s1[i],s3)=0)and(pos(s1[i],s2)=0) then s3:=s3+s1[i];
if (pos(s1[2],s3)=0)and(pos(s2[i],s1)=0) then s3:=s3+s2[i];
end;
ShowMessage(Format('不同的字符有%d, 它们是(%s)', [length(s3), s3]));
end;
运行结果
---------------------------
test
---------------------------
不同的字符有4, 它们是(好坏啊吗)
---------------------------
OK
---------------------------