Lazarus Pascal
Lazarus Pascal
StringBuilder GetNth
Demonstrates the GetNth 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;
delimiterChar: string;
exceptDoubleQuoted: Boolean;
exceptEscaped: Boolean;
begin
// The GetNth method is handy for getting parts from delimited strings.
// For example:
sb := TStringBuilder.Create;
sb.Append('red,blue,"green,purple",,yellow');
delimiterChar := ',';
exceptDoubleQuoted := True;
exceptEscaped := True;
// Prints "[red]"
WriteLn('[' + sb.GetNth(0,delimiterChar,exceptDoubleQuoted,exceptEscaped) + ']');
// Prints "[blue]"
WriteLn('[' + sb.GetNth(1,delimiterChar,exceptDoubleQuoted,exceptEscaped) + ']');
// Prints "[green,purple]"
WriteLn('[' + sb.GetNth(2,delimiterChar,exceptDoubleQuoted,exceptEscaped) + ']');
// Prints "[]"
WriteLn('[' + sb.GetNth(3,delimiterChar,exceptDoubleQuoted,exceptEscaped) + ']');
// Prints "[yellow]"
WriteLn('[' + sb.GetNth(4,delimiterChar,exceptDoubleQuoted,exceptEscaped) + ']');
// Prints "[]"
WriteLn('[' + sb.GetNth(5,delimiterChar,exceptDoubleQuoted,exceptEscaped) + ']');
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.