Lazarus Pascal
Lazarus Pascal
Get a Substring by Char Index and Length
Demonstrates how to use the GetRange method to get a substring by index and length.Note: This example demonstrates the GetRange method which was added in Chilkat v9.5.0.87.
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
success: Boolean;
sb: TStringBuilder;
removeFlag: Boolean;
result: string;
begin
success := False;
sb := TStringBuilder.Create;
// Load a file that contains this string: 0123456789ABCDEF
success := sb.LoadFile('qa_data/txt/remove_chars.txt','utf-8');
// Return "56789A" from the string.
// if removeFlag is True, the returned string is also removed from the sb.
removeFlag := True;
result := sb.GetRange(5,6,removeFlag);
WriteLn(result);
WriteLn(sb.GetAsString());
// Output is:
//
// 56789A
// 01234BCDEF
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.