2陣列比較的問題 |
答題得分者是:jow
|
62590
一般會員 發表:4 回覆:0 積分:0 註冊:2004-09-07 發送簡訊給我 |
|
huwk
資深會員 發表:26 回覆:340 積分:323 註冊:2002-04-03 發送簡訊給我 |
給你個例子.下面的A及B是以0為基底的字串陣列! 例子是比較出.存在B的元素.你可以改寫成你要的
var i , j :integer; inb :boolean; begin for i := 0 to high(a) do begin inb := false; for j := 0 to high(b) do begin if a[i] = b[j] then inb := true; end; if inb then showmessage('Get :"' a[i] '" in array b'); end; end;發表人 - huwk 於 2005/11/16 18:54:13
------
熊的學習 http://huwk.blogspot.com |
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
type TCharSet = set of Char; procedure TForm1.Button1Click(Sender: TObject); var bSet: TCharSet; I, Index: Integer; KeyList: TStringList; Key: string; begin //當array a,b 內含值為字元時 bSet := []; for I := 0 to Length(b)-1 do bSet := bSet [b[I]]; for I := 0 to Length(a)-1 do if not (a[I] in bSet) then Print(a[I]); //當array a,b 內含值為數值時 KeyList := TStringList.Create; try KeyList.Duplicates := dupIgnore; KeyList.Sort := True; for I := 0 to Length(b)-1 do KeyList.Add(Format('.10d',[b[I]])); for I := 0 to Length(a)-1 do begin Key := Format('.10d',[a[I]]); if not KeyList.Find(Key, Index) then Print(a[I]); end; finally KeyList.Free; end; //當array a,b 內含值為字串時 KeyList := TStringList.Create; try KeyList.Duplicates := dupIgnore; KeyList.Sort := True; for I := 0 to Length(b)-1 do KeyList.Add(b[I]); for I := 0 to Length(a)-1 do if not KeyList.Find(a[I], Index) then Print(a[I]); finally KeyList.Free; end; end;發表人 - jow 於 2005/11/28 16:14:07 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |