Trim URL to Root

delphi

Solution

Example code using Indy's `TIdURI` might be:

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;

Problem

How can this be done in Delphi? For example.. URL = https://mail.google.com/mail/u/0/?tab=wm#inbox Trimed URL = https://mail.google.com/ Thanks

Original source