Hi,
How can I remove any duplicates from a string var ?
I need auto cleaning the string from any kinde of duplicate characters.
Thanks,
Z.
function RemoveDuplicateChars(const S: String): String;
var
AlreadyVisited: array[#0..High(Char)] of Boolean;
I: Integer;
begin
FillChar(AlreadyVisited, SizeOf(AlreadyVisited), 0);
Result := '';
for I := 1 to length(S) do
begin
if not AlreadyVisited[S[I]] then
begin
Result := Result + S[I];
AlreadyVisited[S[I]] := True;
end;
end;
end;
Users browsing this forum: No registered users and 0 guests