chiwan
asked on
How to parse a URL?
if they is a URL like:
http://www.firstdomain.com/cgi-bin/serv?url=http://www.seconddomain.com/product.asp?url=http://www.thirddomain.com/detail.asp?pid=40987
I only want:
http://www.thirddomain.com/detail.asp?pid=40987
How to parse it out?
Thanks
Chiwan
http://www.firstdomain.com/cgi-bin/serv?url=http://www.seconddomain.com/product.asp?url=http://www.thirddomain.com/detail.asp?pid=40987
I only want:
http://www.thirddomain.com/detail.asp?pid=40987
How to parse it out?
Thanks
Chiwan
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
function GetURL(S : string; URLPos : Integer) : string;
var
I, BPos, EPos : Integer;
URL : string;
begin
I := 0;
URL := S;
while I <> URLPos do
begin
BPos := Pos('http://', URL);
URL := Copy(URL, BPos + 7, Length(URL) - BPos);
Inc(I);
end;
if Pos('http://', URL) <> 0 then
begin
EPos := Pos('http://', URL);
Result := 'http://' + Copy(URL, 0, EPos - 1);
end
else
Result := 'http://' + URL;
end;
procedure TForm1.Button1Click(Sender
begin
ShowMessage(GetURL('http://www.firstdomain.com/cgi-bin/serv?url=http://www.seconddomain.com/product.asp?url=http://www.thirddomain.com/detail.asp?pid=40987', 3));
end;
With the above example you can extract any URL from a string like you gave in your question.
Cheers,
Alan