Sample code for 30+ languages & platforms
Lazarus Pascal

StringBuilder RemoveAfterFinal

Demonstrates the StringBuilder.RemoveAfterFinal method.

The GetBefore method was added in Chilkat v9.5.0.77

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
  success: Boolean;
  sb: TStringBuilder;
  marker: string;
  bFound: Boolean;

begin
  success := False;

  sb := TStringBuilder.Create;
  success := sb.Append('abc::def::ghi');

  //  The RemoveAfterFinal method removes the chars after the final occurrence of the marker.
  //  It also removes the marker string.
  //  If the marker is not found, then nothing is removed and the method returns False.
  marker := '::';
  bFound := sb.RemoveAfterFinal(marker);

  WriteLn('bFound = ' + bFound);
  WriteLn('sb contains: ' + sb.GetAsString());

  //  Output is:
  //  bFound = True
  //  sb contains: abc::def


  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.