Solved

How to work with links in delphi?

Posted on 2011-03-05
6
452 Views
Last Modified: 2012-05-11
Hello experts.
please help me.

I need to create a function that eliminate all from a link. To understand me example:
i have a list of website in format (http://www.prokredo.ru/forum/index.php), for example.
This function need to delete all from this link, result need to be this : (http://www.prokredo.ru).
Please help me. I need this.
Function need to delete strings '/', 'forum', 'index', '.php'...but to save the 'http://'

Please, help me.
Thanks
0
Comment
Question by:helyonprime96
6 Comments
 
LVL 36

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 35043127
you could use posex
delete all as from 3rd /

url = 'http://www.test.com/subtests/index.php'

function findbaseurl(url: string): string;
var n: integer;
begin
  n := posex('/', url, 8);
  if n > 0 then
    delete(url, n, length(url));
  result := url;
end;
0
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 35043129
you need unit StrUtils;

uses StrUtils;
0
 

Author Comment

by:helyonprime96
ID: 35043140
wow.great.
thanks.

im testing it
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 9

Expert Comment

by:Mahdi78
ID: 35043691
To get the main domain from any link try this

function GetFullMainDomain(Url : string) : string;
var ListDomain : TStringList;
begin
if url = '' then Exit;
ListDomain := TStringList.Create;
  try
  Url := Trim(Url);
  ExtractStrings(['/'], [' '], PChar(Url), ListDomain);
  Result := ListDomain.Strings[0];
  if Pos('https://www.', Url) > 0 then Delete( Url, 1, 12)
  else if Pos('http://www.', Url) > 0 then Delete( Url, 1, 11)
  else if Pos('ftp://www.', Url) > 0 then Delete( Url, 1, 10)
  else if Pos('https://', Url) > 0 then Delete( Url, 1, 8)
  else if Pos('http://', Url) > 0 then Delete( Url, 1, 7)
  else if Pos('ftp://', Url) > 0 then Delete( Url, 1, 6);
  Url := Copy(Url, 1, (Pos('/', Url) - 1));
  ExtractStrings(['.'], [' '], PChar(Url), ListDomain);
  Result := Result +'//www.'+ ListDomain.Strings[ListDomain.Count - 2]+'.'+ ListDomain.Strings[ListDomain.Count - 1];
  finally
  ListDomain.Free;
  end;
end;

For more information take look here
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_25157273.html
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 35045016

Don't assume any text positions, search for the text '//' first

function FormatURL(const AUrl: string): string;
var
  Index: Integer;
begin
  Result := Trim(AUrl);
  Index := Pos('//', Result);
  if Index > 0 then
  begin
    Inc(Index, 2);
    Index := PosEx('/', Result, Index);
    if Index > 0 then
      Result := Copy(Result, 1, Index-1);
  end;
end;

test
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(FormatURL('http://www.prokredo.ru/forum/index.php'));
end;
0
 

Author Closing Comment

by:helyonprime96
ID: 35046306
thanks
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now