簡體   English   中英

修剪URL根目錄

[英]Trim URL to Root

如何在Delphi中完成? 例如..

網址= https://mail.google.com/mail/u/0/?tab=wm#inbox

修剪過的網址= https://mail.google.com/

謝謝

使用Indy的TIdURI示例代碼可能是:

uses
  IdURI;

function GetProtoAndHost(const URI: string): string;
var
  IdURI: TIdURI;
begin
  IdURI := TIdURI.Create(URI);
  try
    Result := IdURI.Protocol + '://' + IdURI.Host + '/';
  finally
    IdURI.Free;
  end;
end;
Function GetRoot(const Path:String):String;
var
 i:Integer;
begin
  i := Pos('//',Path);
  if i>0 then
      i := PosEx('/',Path,i+2)
  else i := Pos('/',Path);
  if i=0 then i := Length(Path);

  Result := Copy(Path,1,i);
end;

看一下Indy的TIdURI類(在“ IdURI”單元中)。 這是一個URI / URL解析器。 您為它提供一個URL,並將其解析為各個組件。 試一試,看看它是如何工作的。 解析URL后,可以通過查看Host和Protocol屬性來回答您的特定問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM