A-man Posted June 22, 2011 Share Posted June 22, 2011 Is there a way to eliminate all the duplicates in an array? Someone made me a function to get the unique characters from a string, and I tried using that concept but I'm not very familiar with arrays. Quote Link to comment Share on other sites More sharing options...
Janilabo Posted June 22, 2011 Share Posted June 22, 2011 Hello A-man, Here is my procedures I made just few months ago.. Hopefully they help you out. deleteDuplicateIntegers: [scar]procedure deleteDuplicateIntegers(var TIA: TIntegerArray); var i, i2, h, t: Integer; tmpTIA: TIntegerArray; b, za: Boolean; begin h:= High(TIA); SetArrayLength(tmpTIA, (h + 1)); for i:= 0 to h do begin for i2:= 0 to t do begin b:= (TIA = tmpTIA[i2]); if(TIA = 0)then if(not(za))then begin za:= True; Break; end; if(b)then Break; end; if(not(b)or(i = 0))then begin tmpTIA[t]:= TIA; Inc(t); end else b:= False; end; SetArrayLength(TIA, 0); SetArrayLength(tmpTIA, t); TIA:= tmpTIA; SetArrayLength(tmpTIA, 0); end;[/scar] deleteDuplicateExtendeds: [scar]procedure deleteDuplicateExtendeds(var TEA: TExtendedArray); var i, i2, h, t: Integer; tmpTEA: TExtendedArray; b, za: Boolean; begin h:= High(TEA); SetArrayLength(tmpTEA, (h + 1)); for i:= 0 to h do begin for i2:= 0 to t do begin b:= (TEA = tmpTEA[i2]); if(TEA = 0)then if(not(za))then begin za:= True; Break; end; if(b)then Break; end; if(not(b)or(i = 0))then begin tmpTEA[t]:= TEA; Inc(t); end else b:= False; end; SetArrayLength(TEA, 0); SetArrayLength(tmpTEA, t); TEA:= tmpTEA; SetArrayLength(tmpTEA, 0); end;[/scar] deleteDuplicateStrings: [scar]procedure deleteDuplicateStrings(var x: TStringArray); var tmp: TStringArray; i, i2, h, cs: Integer; begin h:= High(x); if(h < 1)then Exit; SetArrayLength(tmp, (h + 1)); for i:= 0 to h do begin for i2:= 0 to cs do if(tmp[i2] = x)then Break; if(i2 > cs)then begin tmp[cs]:= x; Inc(cs); end; end; SetArrayLength(x, 0); x:= tmp; SetArrayLength(x, cs); SetArrayLength(tmp, 0); end;[/scar] -Jani Quote Link to comment Share on other sites More sharing options...