有两个等长的字符串A串和串,从左到右一个个进行比较,如果发现3个不一样就退出比较过程。程序怎么写比较简单。
var
A,B:string;
begin
A:='123ABC';
B:='123AEF';
//这两个字符串比较会返回true,因为只有两个不同
//如B:='123mid';就会返回false,因为有三个不一样了end;
var
A,B:string;
begin
A:='123ABC';
B:='123AEF';
//这两个字符串比较会返回true,因为只有两个不同
//如B:='123mid';就会返回false,因为有三个不一样了end;
M:=COPY(A,1,3);
N:=COPY(B,1,3);
IF M=N THEN
RETURN TRUE;
当计数>3时就跳出比较,返回False
vInt ,vLength : Integer;
M , N :String;
begin
vInt := 0 ;
vLength := 1;
while (vInt < 3) and (vLength > Length(A)) then
begin
if COPY(A,vLength,1) = COPY(B,vLength,1) then
Inc(vInt);
vLength(vLength);
end;
j:integer;
A,B,temps:string;
begin
j:=0
for i:=1 to length(A) do begin
if A[i]<>B[i] then j:=j+1;
if j>2 then break;
end;end;
var
i,j,k:integer;
M,N:string;
begin
k:=0 ;
i:=length(a);
for j:=1 to i do
begin
m:=copy(a,j,1);
n:=copy(b,j,1);
if m=n then
continue
else
begin
k:=k+1;
if k=3 then
break;
end;{if}
end;{for}
if k=3 then
Result:=false
else
Result:=true;
end;{begin}上面的函数别忘记在public 中声明啊!!procedure TForm1.Button1Click(Sender: TObject);
var
A,B:string;
i:integer;
begin
A:='163AbC';
B:='123AbF';
if self.compare(a,b) then
showmessage('yes')
else
showmessage('no');
end;
代码风格不大好哦