?
Solved

Remove duplicate URL

Posted on 2008-11-17
4
Medium Priority
?
696 Views
Last Modified: 2013-11-23
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.
0
Comment
Question by:Clubreseau
  • 2
4 Comments
 
LVL 13

Expert Comment

by:ThievingSix
ID: 22981506
Are all domains going to be in the format www.domain.com or will some be domain.com?
0
 

Author Comment

by:Clubreseau
ID: 22981559
some domain www.site.com some domain site.com and some domain site.com/hello.php
0
 
LVL 13

Accepted Solution

by:
ThievingSix earned 2000 total points
ID: 22981685
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
 
LVL 21

Expert Comment

by:ziolko
ID: 22983063
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Screencast - Getting to Know the Pipeline
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question