SysUtilsStrRScan (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This function behaves much like ExtractFileName, except that it uses null-terminated strings and it works only with multi-byte character sets (MBCS).

Code

function NamePart(FileName: PAnsiChar): PAnsiChar;
 var
  P: PAnsiChar;
  sep: Char;
begin
  sep := '/';
  P := StrRScan(FileName, '/');
  if P = nil then
  begin
    P := StrRScan(FileName, ':');
    if P = nil then P := FileName;
  end;
  NamePart := P;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  S : string;
begin
  S := string(NamePart('C:\Test.fil'));
  Canvas.TextOut(10, 10, S);
end;

Uses