[Overview][Types][Procedures and functions][Variables][Index] Reference for unit 'unixutil' (#rtl)

StringToPPChar

Split string in list of null-terminated strings

Declaration

Source position: unixutil.pp line 40

function StringToPPChar(

  S: PChar;

  ReserveEntries: Integer

):PPChar;

function StringToPPChar(

  var S: AnsiString;

  ReserveEntries: Integer

):PPChar;

Description

StringToPPChar splits the string S in words, replacing any whitespace with zero characters. It returns a pointer to an array of pchars that point to the first letters of the words in S. This array is terminated by a Nil pointer.

The function does not add a zero character to the end of the string unless it ends on whitespace.

The function reserves memory on the heap to store the array of PChar; The caller is responsible for freeing this memory.

This function can be called to create arguments for the various Exec calls.

Errors

None.

See also

ArrayStringToPPchar

  

Concert an array of string to an array of null-terminated strings

#rtl.baseunix.FpExecve

  

Execute process using environment

Example

Program Example70;

{ Program to demonstrate the StringToPPchar function. }

Uses UnixUtil;

Var S : String;
    P : PPChar;
    I : longint;

begin
  // remark whitespace at end.
  S:='This is a string with words. ';
  P:=StringToPPChar(S,0);
  I:=0;
  While P[i]<>Nil do
    begin
    Writeln('Word ',i,' : ',P[i]);
    Inc(I);
    end;
  FreeMem(P,i*SizeOf(Pchar));
end.

Documentation generated on: Mar 17 2017