Jump to content
Janilabo

TSAUnique

Recommended Posts

Removes duplicates from array of string. Example included.

 

TSAUnique

[scar]procedure TSAUnique(var TSA: TStringArray);

var

h, h2, i, i2, i3, d: Integer;

begin

h := High(TSA);

if h < 1 then

Exit;

for i := (h - d) downto 1 do

for i2 := (i - 1) downto 0 do

if TSA = TSA[i2] then

begin

h2 := High(TSA);

for i3 := i to (h2 - 1) do

TSA[i3] := TSA[(i3 + 1)];

SetLength(TSA, h2);

Inc(d);

Break;

end;

end;

 

var

h, i: Integer;

TSA: TStringArray;

str: string;

 

begin

ClearDebug;

TSA := ['Test0', 'Test1', 'Test1', 'Test2', 'Test0', 'Test3', 'Test3', 'Test2', 'Test4'];

TSAUnique(TSA);

h := High(TSA);

for i := 0 to h do

if (i < h) then

str := (str + TSA + ', ')

else

str := (str + TSA);

WriteLn(str);

str := '';

SetLength(TSA, 0);

end.[/scar]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...