I have a path say C:\Program Files\Borland what would bet the easiest way to parse that string and just return Borland? thanks
+5
A:
You can get whatever comes after the last backslash with ExtractFileName
, which is found in the SysUtils unit.
Mason Wheeler
2010-05-06 17:40:41
+12
A:
try using the ExtractFileName function, this function only works (for your example) if your path not finalize with an backslash, so you can use the ExcludeTrailingPathDelimiter function to remove the final backslash.
see this sample
program ProjectExtractPathDemo;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
Path : string ;
begin
Path:='C:\Program Files\Borland';
Writeln(ExtractFileName(Path));//return Borland
Path:='C:\Program Files\Borland\';
Writeln(ExtractFileName(Path));//return ''
Path:='C:\Program Files\Borland\';
Writeln(ExtractFileName(ExcludeTrailingPathDelimiter(Path)));//return Borland
Readln;
end.
check this link for more info
RRUZ
2010-05-06 17:41:39
I never know ExtractFileName would work on a directory.Perfect.Thanks.
philO
2010-05-06 17:49:56
A:
To directly parse that string and just return "Borland", you can do this:
uses SysUtils;
Delete(Path, 1, LastDelimiter('\', Path));
lkessler
2010-05-07 02:55:01