Lazarus Pascal
Lazarus Pascal
Get the Last N Lines of a StringBuilder
Returns up to the last N lines of the contents of a Chilkat StringBuilder.Chilkat Lazarus Pascal Downloads
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;
i: Integer;
bCrlf: Boolean;
begin
sb := TStringBuilder.Create;
i := 1;
while i < 100 do
begin
sb.Append('This is line number ');
sb.AppendInt(i);
sb.Append(#13#10);
i := i + 1;
end;
bCrlf := True;
WriteLn(sb.LastNLines(12,bCrlf));
// Output is:
//
// This is line number 88
// This is line number 89
// This is line number 90
// This is line number 91
// This is line number 92
// This is line number 93
// This is line number 94
// This is line number 95
// This is line number 96
// This is line number 97
// This is line number 98
// This is line number 99
//
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.