Remove duplicate URL

I have a memo1 with 1000 URL in,  i want to remove all duplicate domain url in and keep only 1.

www.site.com/hello.php    and   www.site.com/index.html   are same domain i want it delete all duplicate domain URL and keep only 1 with is extension.


THANK YOU 500 point foy you.
ClubreseauAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dagan HooverDeveloperCommented:
Are all domains going to be in the format www.domain.com or will some be domain.com?
0
ClubreseauAuthor Commented:
some domain www.site.com some domain site.com and some domain site.com/hello.php
0
Dagan HooverDeveloperCommented:
This should work:
procedure RemoveDuplicateDomain(Memo: TMemo);
var
  Data : TStringList;
  Domain : String;
  I, J : Integer;
  Count : Integer;
  WWWPos : Integer;
  SLASHPos : Integer;
  DomainIndex : Integer;
begin
  Data := TStringList.Create;
  Data.Text := LowerCase(Memo.Text);
  I := 0;
  Count := Data.Count;
  While I < Count Do
    begin
    Domain := Data.Strings[I];
    WWWPos := Pos('www',Domain);
    SLASHPos := Pos('/',Domain);
    If SLASHPos = 0 Then SLASHPos := Length(Domain);
    If WWWPos > 0 Then
      begin
      Domain := Copy(Domain,WWWPos + 3,SLASHPos - (WWWPos + 3));
    end
    Else
      begin
      Domain := Copy(Domain,1,SLASHPos - 1);
    end;
    J := I + 1;
    While J < Count Do
      begin
      DomainIndex := Pos(Domain,Data.Strings[J]);
      If DomainIndex > 0 Then
        begin
        Data.Delete(J);
        Dec(Count);
        Continue;
      end;
      Inc(J);
    end;
    Inc(I);
  end;
  Memo.Text := Data.Text;
end;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ziolkoCommented:
try this:

uses Wininet;

function GetDomain(AURL: string):string;
var comps: URL_COMPONENTS;
    hs, pth: string;
begin
  FillChar(comps, SizeOf(comps), 0);
  comps.dwStructSize := SizeOf(comps);
  comps.dwHostNameLength := 1;
  comps.dwUrlPathLength := 1;
  if InternetCrackUrl(PChar(AURL), Length(AURL), 0, comps) then begin
    hs := comps.lpszHostName;
    pth := comps.lpszUrlPath;
    Delete(hs, Pos(pth, hs), MaxInt);
    Result := hs;
  end else
    Result := '';
end;

procedure TForm1.Button6Click(Sender: TObject);
var sl: TStringList;
    cnt: Integer;
begin
  sl := TStringList.Create;
  try
    sl.Sorted := True;
    sl.Duplicates := dupIgnore;
    for cnt := 0 to Memo1.Lines.Count - 1 do
      sl.Add(GetDomain(Memo1.Lines[cnt]));
    Memo1.Lines.Assign(sl);
  finally
    sl.Free;
  end;
end;


ziolko.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.