Ultimate Sidebar

Code a Custom ExtractBasePath Delphi Function

106 27
Question: Code a Custom ExtractBasePath Delphi Function

Challenge: a custom Delphi function, ExtractBasePath, should take 2 path names (directory or file) and should return the base / common path for the two paths provided.

The code is submitted for the ExtractBasePath Delphi Challenge

Answer:

ExtractBasePath entry by Boris Kumpar:

function ExtractBasePath(const Path1,Path2:string):string; const   PATH_DELIMITER = '\';   DRIVE_DELIMITER = ':'; var   P1,P2:PChar;   cnt,j:Integer; begin   P1:=PChar(Path1) ;   P2:=PChar(Path2) ;  cnt := 1;   j := 0;   {$B-}   while (P1^ <> #0) and (P2^ <> #0) and (UpCase(P1^) = UpCase(P2^) ) do   begin     if (P1^=PATH_DELIMITER) or (P2^=PATH_DELIMITER) or ((j=0) and (P1^=DRIVE_DELIMITER)) then j:=cnt;    Inc(cnt) ;     Inc(P1) ;     Inc(P2) ;   end;  if (P1^=PATH_DELIMITER) or (P2^=PATH_DELIMITER) then j := cnt - 1;  Result:=Copy(Path1,1,j) ; end;

Explore the list of all accepted entries for ExtractBasePath Delphi challenge.
Source: ...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.