Lazarus Pascal
Lazarus Pascal
StringBuilder ReplaceBetween
Demonstrates the ReplaceBetween method.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;
numReplacements: Integer;
begin
sb := TStringBuilder.Create;
sb.Append('<company><industry>Software</industry><name>Chilkat Software</name><abc>Abc Software</abc><name>Xyz Software</name></company>');
// The ReplaceBetween method restricts the replacements to only
// the parts that occur between two delimiter strings.
// For example:
numReplacements := sb.ReplaceBetween('<name>','</name>','Software','Technology');
// The number of replacements should be 2.
WriteLn('numReplacements = ' + numReplacements);
// The sb now contains:
// <company><industry>Software</industry><name>Chilkat Technology</name><abc>Abc Software</abc><name>Xyz Technology</name></company>
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.