Sample code for 30+ languages & platforms
Lazarus Pascal

StringTable SplitAndAppend Example

Demonstrates the StringTable SplitAndAppend method.

Chilkat Lazarus Pascal Downloads

Lazarus Pascal
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.StringTable;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  strTab: TStringTable;
  s: string;
  i: Integer;
  numStrings: Integer;

begin
  strTab := TStringTable.Create;

  //  SplitAndAppend make it easy to break apart comma delimited, semicolon delimited,
  //  or strings delimited by other characters.
  s := 'abc,123,xyz,456,music,math,"World History","Chicago,Cubs",Japan';

  strTab.SplitAndAppend(s,',',True,True);

  i := 0;
  numStrings := strTab.Count;
  while i < numStrings do
    begin
      WriteLn(i + ': ' + strTab.StringAt(i));
      i := i + 1;
    end;

  //  The output is: 
  //  0: abc
  //  1: 123
  //  2: xyz
  //  3: 456
  //  4: music
  //  5: math
  //  6: "World History"
  //  7: "Chicago,Cubs"
  //  8: Japan

  //  Note: Keeping the quotes is intentional.


  strTab.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.