Главная страница | назад





Article #28478: How to remove the backslash from the end of a path.

QUESTION:

How can I make sure there is no backslash at the end of a path?

ANSWER:

Delphi has a function called: ExcludeTrailingPathDelimiter. This will return a string with one backslash '/' removed from the end if it has one (or more). Below is one example of how this function works. There is another function called: ExcludeTrailingBackslash, this is only included for backwards compatibility (this function should not be used).


procedure TForm1.Button1Click(Sender: TObject);
var
DirPath : string;
begin
DirPath := Edit1.Text;
ShowMessage(ExcludeTrailingPathDelimiter(DirPath));
end;

Last Modified: 28-FEB-02