[fpc-pascal] Remove last character from pchar
Jean SUZINEAU
jean.suzineau at wanadoo.fr
Fri Jun 11 00:21:05 CEST 2021
I think you could just manage the end of your string with a #0 char.
Just allocate enough space for the maximum size of your string plus the
terminal #0 char.
For example
program Project1;
{$mode objfpc}{$H+}
uses
SysUtils, Classes;
var
s: array[0..30] of char;
p: PChar;
begin
p:= @s;
StrPLCopy( p, 'Test', 30);
Writeln( p);
s[3]:= #0;
Writeln( p);
end.
produces
$ ./project1
Test
Tes
$
More information about the fpc-pascal
mailing list