寻找并归类相差2个字符的字符串(100)

冬月

Unregistered / Unconfirmed
GUEST, unregistred user!
在listbox中有很多个字符串,把其中相差2个字符的归类出来放入memo中,比如:aaaaa111122223333ddd4432d332422x22aaaaa311142223333bbbbbee3342344444ddd44w2d332422222归类好后memo中应该是:*********************aaaaa111122223333aaaaa311142223333*********************ddd4432d332422x22ddd44w2d332422222*********************
 
function CompStr(ps1,ps2:pChar):Boolean;var iCount:Integer;begin result:=False
iCount:=abs(strlen(ps1)-strlen(ps2))
if iCount>2 then exit
while (ps1^<>#0) and (ps2^<>#0) do begin if ps1^<>ps2^ then inc(iCount)
inc(ps1)
inc(ps2)
end
result:=iCount=2;end;procedure TForm1.Button1Click(Sender: TObject);var i,j,iCount:Integer
s1,s2:string
used:array of Integer;begin iCount:=ListBox1.Count-1
if iCount<=0 then exit
Memo1.Clear
SetLength(used,iCount+1)
try for i:=0 to iCount do begin s1:=ListBox1.Items
if used=1 then Continue
for j:=1 to iCount do begin if used[j]=1 then Continue
s2:=ListBox1.Items[j]
if CompStr(PChar(s1),PChar(s2)) then begin Memo1.Lines.Add('***********************************')
Memo1.Lines.Add(s1)
Memo1.Lines.Add(s2)
Memo1.Lines.Add('***********************************')
Memo1.Lines.Add('')
used[j]:=1
end
end
end
finally used:=nil
end;end;
 
aaaaa111122223333ddd4432d332422x22aaaaa311142223333axaaa311142223433bbbbbee3342344444ddd44w2d332422222上面的代码测试了下,像这样的就不能正确判断出来
 
...... if CompStr(PChar(s1),PChar(s2)) thenbegin Memo1.Lines.Add('***********************************')
Memo1.Lines.Add(s1)
Memo1.Lines.Add(s2)
Memo1.Lines.Add('***********************************')
Memo1.Lines.Add('')
used[j]:=1;//将这行改为used:=1;end;......
 

Similar threads

回复
0
查看
862
不得闲
S
回复
0
查看
955
SUNSTONE的Delphi笔记
S
S
回复
0
查看
777
SUNSTONE的Delphi笔记
S
D
回复
0
查看
745
DelphiTeacher的专栏
D
顶部