Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Base Url aus LocationURL Finden (https://www.delphipraxis.net/165587-base-url-aus-locationurl-finden.html)

Gandimann 6. Jan 2012 19:00

Delphi-Version: XE

Base Url aus LocationURL Finden
 
Hi Friends,
wie kann ich aus einem gegebenen LocationURL den BaseURL herausfiltern ?

z.B.

gegebene LocationURL = 'http://www.baseurl.com/xyz/abc/lmn.html'

ich möchte baseURL 'http://www.baseurl.com/' herausfiltern.

Ich griege das nicht gebacken:oops::shock:

Bin dankbar für jede Hilfe :)

Gandimann

s.h.a.r.k 6. Jan 2012 19:23

AW: Base Url aus LocationURL Finden
 
Delphi-Quellcode:
function ExtractBaseUrlFromGeneralUrl(Url: string): string;
var
  Index : Integer;
  Protocol : string;
  PathExists : Boolean;
begin
  // if (not IsValidUrl(Url)) then
  //   raise Exception.Create(...);

  // Remove http://, https://, ftp://
  Index := Pos('://', Url);
  Protocol := Copy(Url, 1, Index + 2);
  Writeln(Protocol);
  Delete(Url, 1, Index + 2);

  // Remove path if there is any at the and of the url
  Index := Pos('/', Url);
  PathExists := (Index > 0);
  if (PathExists) then
    Delete(Url, Index, Length(Url));

  Result := Protocol + Url;
end;
Nun eine korrekte Version... Hatte das Protokoll vergessen...

Gandimann 6. Jan 2012 20:43

AW: Base Url aus LocationURL Finden
 
Liste der Anhänge anzeigen (Anzahl: 1)
Zitat:

Zitat von s.h.a.r.k (Beitrag 1144720)
Delphi-Quellcode:
function ExtractBaseUrlFromGeneralUrl(Url: string): string;
var
  Index : Integer;
  Protocol : string;
  PathExists : Boolean;
begin
  // if (not IsValidUrl(Url)) then
  //   raise Exception.Create(...);

  // Remove http://, https://, ftp://
  Index := Pos('://', Url);
  Protocol := Copy(Url, 1, Index + 2);
  Writeln(Protocol);
  Delete(Url, 1, Index + 2);

  // Remove path if there is any at the and of the url
  Index := Pos('/', Url);
  PathExists := (Index > 0);
  if (PathExists) then
    Delete(Url, Index, Length(Url));

  Result := Protocol + Url;
end;
Nun eine korrekte Version... Hatte das Protokoll vergessen...

Leider kommt ein I/O error 105

siehe Test Project

Luckie 6. Jan 2012 20:50

AW: Base Url aus LocationURL Finden
 
Hast du auch eine Konsolenanwendung erstellt? Das Writeln (wohl zu Debug-Zwecken) erfordert eine Konsolenanwendung.

Gandimann 6. Jan 2012 21:01

AW: Base Url aus LocationURL Finden
 
Zitat:

Zitat von Luckie (Beitrag 1144734)
Hast du auch eine Konsolenanwendung erstellt? Das Writeln (wohl zu Debug-Zwecken) erfordert eine Konsolenanwendung.

Ne ne nee..

Mit Konsolenanwendung habe ich keine Erfahrung...


daher brauch ich Hilfe für normalen Form Anwendung.

Sir Rufo 6. Jan 2012 21:21

AW: Base Url aus LocationURL Finden
 
aua

warum kommentierst du denn nicht das WriteLn aus? :roll:

Gandimann 6. Jan 2012 21:44

AW: Base Url aus LocationURL Finden
 
Sir Rufo war schneller bevor ich antworten konnte ....:-D

Nevermind....

habe wirteln ins Showmessage geändert... und funzt perfekt...:-D:thumb::thumb:


Danke S.H.A.R.K
Danke Lukie
Danke Sir Rufo

s.h.a.r.k 6. Jan 2012 21:48

AW: Base Url aus LocationURL Finden
 
Wirf doch die Zeile ganz raus :D Das Ding was nur zum Testen drin :stupid:

Wichtig wäre nach so einem Fehler vor allem auch, dass du den Code verstehst und nicht nur blind kopierst ;) Nur so für die Zukunft...


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:19 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz