Sample code for 30+ languages & platforms
Lazarus Pascal

StringBuilder GetAfterBetween

Demonstrates the GetAfterBetween 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.StringBuilder;

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

procedure RunDemo;
var
  sb: TStringBuilder;
  searchAfter: string;
  companyName: string;

begin
  sb := TStringBuilder.Create;
  sb.Append('<abc><person><name>Joe</name></person><company><name>Chilkat Software</name></company></abc>');

  //  The GetAfterBetween method gets the substring between two arbitrary marker strings, and doesn't
  //  start searching until the searchAfter string is passed.

  //  For example, to get the company name in the string above...
  searchAfter := '<company>';
  companyName := sb.GetAfterBetween(searchAfter,'<name>','</name>');
  WriteLn('Company Name = ' + companyName);


  sb.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.