Sample code for 30+ languages & platforms
Lazarus Pascal

StringBuilder GetEncoded

Demonstrates the Chilkat StringBuilder GetEncoded 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
  s: string;
  sb: TStringBuilder;

begin
  s := 'The quick brown fox jumps over the lazy dog';

  sb := TStringBuilder.Create;

  sb.Append(s);

  //  output: The quick brown fox jumps over the lazy dog
  WriteLn(sb.GetAsString());

  //  Get the string encoded to base64, without changing the contents of sb.
  //  output: VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==
  WriteLn(sb.GetEncoded('base64','utf-8'));

  //  The contents of sb are not changed..
  //  output: The quick brown fox jumps over the lazy dog
  WriteLn(sb.GetAsString());


  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.