---
product: Chilkat
product_version: 11.7.0
language: pascal
language_label: Lazarus Pascal
class: StringArray
license: free
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/pascal_StringArrayRef.html
---
# Chilkat StringArray — Lazarus Pascal — v11.7.0

> Chilkat 11.7.0 · language=pascal · class=StringArray
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/StringArray.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/pascal/guide.md`.

## Purpose

**Manage an ordered collection of strings, with StringTable recommended for new code.**

`Chilkat.StringArray` is an ordered string-collection class that can append, prepend, insert, replace, remove, pop, and retrieve strings by index. It can load one string per line from files or in-memory text, save the collection back to text or files, enforce uniqueness, trim incoming values, normalize line endings, search by exact value or wildcard pattern, sort entries, split text into entries, serialize and restore the collection, and perform set-style operations such as union and subtraction.

**Recommendation:** For new development, prefer `Chilkat.StringTable` instead of `Chilkat.StringArray`. `StringTable` provides a simpler, faster, and more memory-efficient way to manage ordered lists of strings. Use `StringArray` primarily when maintaining existing code or when a specific API or older example already uses it.

**Ordered string collection**

Store strings in an internal ordered collection and retrieve them by zero-based index using `GetString`, `StrAt`, or `LastString`.

**Add and modify entries**

Append, prepend, insert, replace, remove, clear, or pop strings as the collection changes.

**Load and save text**

Load one string per line from files or text, and save the collection back to files or a single line-delimited string.

**Charset-aware file I/O**

Use charset-specific load and save methods when working with UTF-8, UTF-16, or other non-ANSI text encodings.

**Search, match, and sort**

Check for exact strings, find values from a starting index, match wildcard patterns, and sort ascending or descending.

**Serialize and combine**

Serialize the collection for later restoration, split text into entries, and combine or subtract collections with set-style operations.

**Common pattern:** Create a `StringArray`, optionally set `Trim`, `Crlf`, or `Unique`, then append strings directly or load them from a file or text block. Search, sort, split, remove, union, or subtract entries as needed, then save the result with `SaveToText`, `SaveToFile`, or `SaveToFile2`. For new code that only needs an ordered list of strings, use `Chilkat.StringTable` instead.

**Naming note:** Although the class name contains `Array`, `Chilkat.StringArray` is a Chilkat object that manages an ordered string collection. It should not be confused with a native array type in a programming language.

## Object creation, unlocking and error handling

**Create / Free**

```pascal
uses
  Chilkat.StringArray;

var
  obj: TStringArray;
begin
  obj := TStringArray.Create;
  try
    if not obj.IsValid then
      raise Exception.Create('Failed to create a TStringArray instance.');

    // ... use obj ...

  finally
    obj.Free;
  end;
end;
```

`constructor Create;`

Allocates the underlying CkStringArray object and returns a new TStringArray instance. Simply adding **Chilkat.StringArray** to the unit's `uses` clause is enough to locate and bind to the Chilkat shared library (DLL / .so / .dylib) at runtime — no separate load step is required. Check `obj.IsValid` after calling `Create`; it is `False` if the underlying library could not be found/loaded or the object could not be allocated (for example, when unlicensed).

`destructor Destroy; override;`

Every TStringArray created by calling `Create` should eventually be released by calling `.Free` (inherited from `TObject`). The destructor automatically disposes the underlying CkStringArray handle. A native (unmanaged) memory leak occurs if the object is never freed.

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in Lazarus Pascal.

## Members common to every Chilkat class

Documented once per language in `common-members.md`; listed here so this page is self-contained.

| Property | Signature | Access | Meaning |
|---|---|---|---|
| `DebugLogFilePath` | `property DebugLogFilePath: string read GetDebugLogFilePath write SetDebugLogFilePath;` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastErrorHtml` | `property LastErrorHtml: string read GetLastErrorHtml;` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `property LastErrorText: string read GetLastErrorText;` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `property LastErrorXml: string read GetLastErrorXml;` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `property LastMethodSuccess: Boolean read GetLastMethodSuccess write SetLastMethodSuccess;` | read/write | Indicates the success or failure of the most recent method call: `True` means success, `False` means failure. |
| `VerboseLogging` | `property VerboseLogging: Boolean read GetVerboseLogging write SetVerboseLogging;` | read/write | If set to `True`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `property Version: string read GetVersion;` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `Count` | property, read-only | `property Count: Integer read GetCount;` |
| `Crlf` | property, read/write | `property Crlf: Boolean read GetCrlf write SetCrlf;` |
| `Length` | property, read-only | `property Length: Integer read GetLength;` |
| `Trim` | property, read/write | `property Trim: Boolean read GetTrim write SetTrim;` |
| `Unique` | property, read/write | `property Unique: Boolean read GetUnique write SetUnique;` |
| `Append` | method | `function Append(const str: string): Boolean;` |
| `AppendSerialized` | method | `function AppendSerialized(const encodedStr: string): Boolean;` |
| `Clear` | method | `procedure Clear;` |
| `Contains` | method | `function Contains(const str: string): Boolean;` |
| `Find` | method | `function Find(const findStr: string;     startIndex: Integer): Integer;` |
| `FindFirstMatch` | method | `function FindFirstMatch(const matchPattern: string;     startIndex: Integer): Integer;` |
| `GetString` | method | `function GetString(index: Integer): string;` |
| `GetStringLen` | method | `function GetStringLen(index: Integer): Integer;` |
| `InsertAt` | method | `procedure InsertAt(index: Integer;     const str: string);` |
| `LastString` | method | `function LastString: string;` |
| `LoadFromFile` | method | `function LoadFromFile(const path: string): Boolean;` |
| `LoadFromFile2` | method | `function LoadFromFile2(const path: string;     const charset: string): Boolean;` |
| `LoadFromText` | method | `procedure LoadFromText(const str: string);` |
| `LoadTaskResult` | method | `// task is a TTask object. function LoadTaskResult(task: TChilkatBase): Boolean;` |
| `Pop` | method | `function Pop: string;` |
| `Prepend` | method | `procedure Prepend(const str: string);` |
| `Remove` | method | `procedure Remove(const str: string);` |
| `RemoveAt` | method | `function RemoveAt(index: Integer): Boolean;` |
| `ReplaceAt` | method | `procedure ReplaceAt(index: Integer;     const str: string);` |
| `SaveNthToFile` | method | `function SaveNthToFile(index: Integer;     const saveToPath: string): Boolean;` |
| `SaveToFile` | method | `function SaveToFile(const path: string): Boolean;` |
| `SaveToFile2` | method | `function SaveToFile2(const saveToPath: string;     const charset: string): Boolean;` |
| `SaveToText` | method | `function SaveToText: string;` |
| `Serialize` | method | `function Serialize: string;` |
| `Sort` | method | `procedure Sort(ascending: Boolean);` |
| `SplitAndAppend` | method | `procedure SplitAndAppend(const str: string;     const boundary: string);` |
| `StrAt` | method | `function StrAt(index: Integer): string;` |
| `Subtract` | method | `// stringArrayObj is a TStringArray object. procedure Subtract(stringArrayObj: TChilkatBase);` |
| `Union` | method | `// stringArrayObj is a TStringArray object. procedure Union(stringArrayObj: TChilkatBase);` |

## Properties

### StringArray.Count

`Chilkat 11.7.0 · pascal · StringArray · Count · property · read-only`

```pascal
property Count: Integer read GetCount;
```

The number of strings contained within the object's internal array (i.e. ordered collection).

**Important:** This is an object that contains a collection of strings. Although the class/object name includes the word `Array`, it should not be confused with an array in the sense of the primitive array type used in a given programming language.

### StringArray.Crlf

`Chilkat 11.7.0 · pascal · StringArray · Crlf · property · read/write`

```pascal
property Crlf: Boolean read GetCrlf write SetCrlf;
```

If `True`, strings are always automatically converted to use CRLF line endings. If `False`, strings are automatically converted to use bare LF line endings.

### StringArray.Length

`Chilkat 11.7.0 · pascal · StringArray · Length · property · read-only`

```pascal
property Length: Integer read GetLength;
```

The number of strings contained within the internal collection. (Identical to the Count property.)

### StringArray.Trim

`Chilkat 11.7.0 · pascal · StringArray · Trim · property · read/write`

```pascal
property Trim: Boolean read GetTrim write SetTrim;
```

If `True`, whitespace, including carriage-returns and linefeeds, are automatically removed from the beginning and end of a string when added to the collection.

### StringArray.Unique

`Chilkat 11.7.0 · pascal · StringArray · Unique · property · read/write`

```pascal
property Unique: Boolean read GetUnique write SetUnique;
```

If `True`, then duplicates are not allowed. When an attempt is made to insert a string that already exists, the duplicate insertion is silently suppressed and no error is returned. The default value is `False`.

## Methods

### StringArray.Append

`Chilkat 11.7.0 · pascal · StringArray · Append · method`

```pascal
function  Append(const str: string): Boolean;
```

Appends a string to the end of the internal ordered collection.

Returns True for success, False for failure.

### StringArray.AppendSerialized

`Chilkat 11.7.0 · pascal · StringArray · AppendSerialized · method`

```pascal
function  AppendSerialized(const encodedStr: string): Boolean;
```

Appends multiple strings to the end of the internal ordered collection. The `encodedStr` is what is returned from the Serialize method (see below).

Returns True for success, False for failure.

### StringArray.Clear

`Chilkat 11.7.0 · pascal · StringArray · Clear · method`

```pascal
procedure Clear;
```

Remove all strings from the internal collection.

### StringArray.Contains

`Chilkat 11.7.0 · pascal · StringArray · Contains · method`

```pascal
function  Contains(const str: string): Boolean;
```

Returns `True` if the string is present in the internal collection. The string comparisons are case sensitive.

### StringArray.Find

`Chilkat 11.7.0 · pascal · StringArray · Find · method`

```pascal
function  Find(const findStr: string;
    startIndex: Integer): Integer;
```

Finds the index of the first string equal to `findStr`. The search begins at `startIndex`. If the string is not found, -1 is returned. The first string in the array is at index 0.

### StringArray.FindFirstMatch

`Chilkat 11.7.0 · pascal · StringArray · FindFirstMatch · method`

```pascal
function  FindFirstMatch(const matchPattern: string;
    startIndex: Integer): Integer;
```

Finds the first string that matches the `matchPattern`. The search begins at `startIndex`. If the string is not found, -1 is returned. The first string in the array is at index 0.

The `matchPattern` may contain zero or more asterisk chars, each of which matches 0 or more of any character.

### StringArray.GetString

`Chilkat 11.7.0 · pascal · StringArray · GetString · method`

```pascal
function  GetString(index: Integer): string;
```

Returns the string at an indexed location within the internal collection. The first string is located at index 0.

Returns True for success, False for failure.

### StringArray.GetStringLen

`Chilkat 11.7.0 · pascal · StringArray · GetStringLen · method`

```pascal
function  GetStringLen(index: Integer): Integer;
```

Returns Nth string's length, in characters. The first string is located at index 0.

### StringArray.InsertAt

`Chilkat 11.7.0 · pascal · StringArray · InsertAt · method`

```pascal
procedure InsertAt(index: Integer;
    const str: string);
```

Inserts a string into the internal collection at a specified index. Using index 0 will insert at the beginning.

### StringArray.LastString

`Chilkat 11.7.0 · pascal · StringArray · LastString · method`

```pascal
function  LastString: string;
```

Returns the last string in the internal collection.

Returns True for success, False for failure.

### StringArray.LoadFromFile

`Chilkat 11.7.0 · pascal · StringArray · LoadFromFile · method`

```pascal
function  LoadFromFile(const path: string): Boolean;
```

Loads strings from a file (one per line) into the internal collection. It is assumed the file contains ANSI strings. To load from a file containing non-ANSI strings (such as utf-8), call LoadFromFile2 instead.

**Note:** This method appends the strings in `path` to the existing collection of strings contained in this object.

Returns True for success, False for failure.

### StringArray.LoadFromFile2

`Chilkat 11.7.0 · pascal · StringArray · LoadFromFile2 · method`

```pascal
function  LoadFromFile2(const path: string;
    const charset: string): Boolean;
```

Loads strings from a file (one per line) into the internal collection. The `charset` specifies the character encoding (such as utf-8) of the strings contained in the file.

**Note:** This method appends the strings in `path` to the existing collection of strings contained in this object.

Returns True for success, False for failure.

### StringArray.LoadFromText

`Chilkat 11.7.0 · pascal · StringArray · LoadFromText · method`

```pascal
procedure LoadFromText(const str: string);
```

Loads strings from an in-memory string (one per line) into the internal collection.

**Note:** This method appends the strings in `str` to the existing collection of strings contained in this object.

### StringArray.LoadTaskResult

`Chilkat 11.7.0 · pascal · StringArray · LoadTaskResult · method · since 9.5.0.52`

```pascal
// task is a TTask object.

function  LoadTaskResult(task: TChilkatBase): Boolean;
```

Loads the string collection from a completed asynchronous task.

Returns True for success, False for failure.

### StringArray.Pop

`Chilkat 11.7.0 · pascal · StringArray · Pop · method`

```pascal
function  Pop: string;
```

Returns the last string and removes it from the internal collection.

Returns True for success, False for failure.

### StringArray.Prepend

`Chilkat 11.7.0 · pascal · StringArray · Prepend · method`

```pascal
procedure Prepend(const str: string);
```

Adds a string to the beginning of the internal collection.

### StringArray.Remove

`Chilkat 11.7.0 · pascal · StringArray · Remove · method`

```pascal
procedure Remove(const str: string);
```

Removes all strings equal to the string argument from the internal collection.

### StringArray.RemoveAt

`Chilkat 11.7.0 · pascal · StringArray · RemoveAt · method`

```pascal
function  RemoveAt(index: Integer): Boolean;
```

Removes the string at a particular index.

Returns True for success, False for failure.

### StringArray.ReplaceAt

`Chilkat 11.7.0 · pascal · StringArray · ReplaceAt · method · since 9.5.0.52`

```pascal
procedure ReplaceAt(index: Integer;
    const str: string);
```

Replaces the string at a specified index.

### StringArray.SaveNthToFile

`Chilkat 11.7.0 · pascal · StringArray · SaveNthToFile · method`

```pascal
function  SaveNthToFile(index: Integer;
    const saveToPath: string): Boolean;
```

Saves the Nth string in the collection to a file.

Returns True for success, False for failure.

### StringArray.SaveToFile

`Chilkat 11.7.0 · pascal · StringArray · SaveToFile · method`

```pascal
function  SaveToFile(const path: string): Boolean;
```

Saves the collection of strings to a file, one string per line. Strings are saved using the ANSI charset. (Call SaveToFile2 to specify a charset, such as `utf-8`)

Returns True for success, False for failure.

### StringArray.SaveToFile2

`Chilkat 11.7.0 · pascal · StringArray · SaveToFile2 · method`

```pascal
function  SaveToFile2(const saveToPath: string;
    const charset: string): Boolean;
```

Saves the collection of strings to a file, one string per line. Strings are saved using the specified `charset`.

Returns True for success, False for failure.

### StringArray.SaveToText

`Chilkat 11.7.0 · pascal · StringArray · SaveToText · method`

```pascal
function  SaveToText: string;
```

Writes the collection of strings to a single string, one per line (separated by CRLF line endings).

Returns True for success, False for failure.

### StringArray.Serialize

`Chilkat 11.7.0 · pascal · StringArray · Serialize · method`

```pascal
function  Serialize: string;
```

Returns an string which is an encoded representation of all the strings in the collection. The string collection can be re-created by calling the AppendSerialized method.

Returns True for success, False for failure.

### StringArray.Sort

`Chilkat 11.7.0 · pascal · StringArray · Sort · method`

```pascal
procedure Sort(ascending: Boolean);
```

Sorts the strings in the collection in ascending or descending order. To sort in ascending order, set `ascending` to `True`, otherwise set `ascending` equal to `False`.

### StringArray.SplitAndAppend

`Chilkat 11.7.0 · pascal · StringArray · SplitAndAppend · method`

```pascal
procedure SplitAndAppend(const str: string;
    const boundary: string);
```

Splits a string at a character or substring boundary and adds each resulting string to the internal collection.

### StringArray.StrAt

`Chilkat 11.7.0 · pascal · StringArray · StrAt · method`

```pascal
function  StrAt(index: Integer): string;
```

Returns the string at a specific index.

Returns True for success, False for failure.

### StringArray.Subtract

`Chilkat 11.7.0 · pascal · StringArray · Subtract · method`

```pascal
// stringArrayObj is a TStringArray object.

procedure Subtract(stringArrayObj: TChilkatBase);
```

Subtracts the strings contained within `stringArrayObj` from the caller's internal collection.

### StringArray.Union

`Chilkat 11.7.0 · pascal · StringArray · Union · method`

```pascal
// stringArrayObj is a TStringArray object.

procedure Union(stringArrayObj: TChilkatBase);
```

Performs the union set-operator. The result is that the caller will have a string collection that is the union of itself and `stringArrayObj`.

