[fpc-pascal] RPos Causing Access violation
Bart
bartjunk64 at gmail.com
Tue May 21 18:50:23 CEST 2019
On Tue, May 21, 2019 at 2:18 PM James Richters
<james at productionautomation.net> wrote:
> Function ExtractFilePathAndNameWithoutExt(Filenametouse:String):String;
>
> Begin
>
> ExtractFilePathAndNameWithoutExt := copy(Filenametouse,1,rpos(ExtractFileExt(Filenametouse),Filenametouse)-1);
>
> End;
>From LazFileUtils unit:
function ExtractFileNameWithoutExt(const AFilename: string): string;
var
p: Integer;
begin
Result:=AFilename;
p:=length(Result);
while (p>0) do begin
case Result[p] of
PathDelim: exit;
{$ifdef windows}
'/': if ('/' in AllowDirectorySeparators) then exit;
{$endif}
'.': exit(copy(Result,1, p-1));
end;
dec(p);
end;
end;
writeln(ExtractFileNameWithoutExt('c:\foo\bar\foobar.ext'));
gives:
c:\foo\bar\foobar
--
Bart
More information about the fpc-pascal
mailing list