[fpc-devel] copy for PChar

Sergei Gorelkin sergei_gorelkin at mail.ru
Sun Feb 19 18:02:00 CET 2012


19.02.2012 20:34, Mattias Gaertner пишет:
>
> Is there already a function
>
> function Copy(StartPos: PChar; Count: PtrUInt; StopAt0: boolean =
> true): string;
>
I don't know about an already existing such function (well, actually SetString used to work that way 
in the past, but no longer), but here's one (assuming StartPos<>nil):

var
   len: sizeint;
begin
   if StopAt0 then
   begin
     len:=IndexByte(StartPos^,Count,0);
     if len=-1 then
       len:=Count;
   end
   else
     len:=Count;
   SetString(result,StartPos,len);
end;

Regards,
Sergei



More information about the fpc-devel mailing list