---
product: Chilkat
product_version: 11.7.0
language: wc
language_label: Unicode C
class: StringArray
license: free
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/wc_CkStringArrayWRef.html
---
# Chilkat StringArray — Unicode C — v11.7.0

> Chilkat 11.7.0 · language=wc · 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/wc/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/Dispose**

```c
HCkStringArrayW instance = CkStringArrayW_Create();
// ...
CkStringArrayW_Dispose(instance);
```

`HCkStringArrayW CkStringArrayW_Create(void);`

Creates an instance of the HCkStringArrayW object and returns a handle ("void \*" pointer). The handle is passed in the 1st argument for the functions listed on this page.

`void CkStringArrayW_Dispose(HCkStringArrayW handle);`

Objects created by calling CkStringArrayW_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function. Also, any handle returned by a Chilkat "C" function must also be freed by the application by calling the appropriate Dispose method, such as CkStringArrayW_Dispose.

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 Unicode C.

## 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` | `void CkStringArrayW_getDebugLogFilePath(HCkStringArrayW cHandle, HCkString retval); void CkStringArrayW_putDebugLogFilePath(HCkStringArrayW cHandle, const wchar_t *newVal); const wchar_t *CkStringArrayW_debugLogFilePath(HCkStringArrayW cHandle);` | 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` | `void CkStringArrayW_getLastErrorHtml(HCkStringArrayW cHandle, HCkString retval); const wchar_t *CkStringArrayW_lastErrorHtml(HCkStringArrayW cHandle);` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `void CkStringArrayW_getLastErrorText(HCkStringArrayW cHandle, HCkString retval); const wchar_t *CkStringArrayW_lastErrorText(HCkStringArrayW cHandle);` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `void CkStringArrayW_getLastErrorXml(HCkStringArrayW cHandle, HCkString retval); const wchar_t *CkStringArrayW_lastErrorXml(HCkStringArrayW cHandle);` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `BOOL CkStringArrayW_getLastMethodSuccess(HCkStringArrayW cHandle); void CkStringArrayW_putLastMethodSuccess(HCkStringArrayW cHandle, BOOL newVal);` | read/write | Indicates the success or failure of the most recent method call: `TRUE` means success, `FALSE` means failure. |
| `VerboseLogging` | `BOOL CkStringArrayW_getVerboseLogging(HCkStringArrayW cHandle); void CkStringArrayW_putVerboseLogging(HCkStringArrayW cHandle, BOOL newVal);` | read/write | If set to `TRUE`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `void CkStringArrayW_getVersion(HCkStringArrayW cHandle, HCkString retval); const wchar_t *CkStringArrayW_version(HCkStringArrayW cHandle);` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `Count` | property, read-only | `int CkStringArrayW_getCount(HCkStringArrayW cHandle);` |
| `Crlf` | property, read/write | `BOOL CkStringArrayW_getCrlf(HCkStringArrayW cHandle); void CkStringArrayW_putCrlf(HCkStringArrayW cHandle, BOOL newVal);` |
| `Length` | property, read-only | `int CkStringArrayW_getLength(HCkStringArrayW cHandle);` |
| `Trim` | property, read/write | `BOOL CkStringArrayW_getTrim(HCkStringArrayW cHandle); void CkStringArrayW_putTrim(HCkStringArrayW cHandle, BOOL newVal);` |
| `Unique` | property, read/write | `BOOL CkStringArrayW_getUnique(HCkStringArrayW cHandle); void CkStringArrayW_putUnique(HCkStringArrayW cHandle, BOOL newVal);` |
| `Append` | method | `BOOL CkStringArrayW_Append(HCkStringArrayW cHandle, const wchar_t *str);` |
| `AppendSerialized` | method | `BOOL CkStringArrayW_AppendSerialized(HCkStringArrayW cHandle, const wchar_t *encodedStr);` |
| `Clear` | method | `void CkStringArrayW_Clear(HCkStringArrayW cHandle);` |
| `Contains` | method | `BOOL CkStringArrayW_Contains(HCkStringArrayW cHandle, const wchar_t *str);` |
| `Find` | method | `int CkStringArrayW_Find(HCkStringArrayW cHandle, const wchar_t *findStr, int startIndex);` |
| `FindFirstMatch` | method | `int CkStringArrayW_FindFirstMatch(HCkStringArrayW cHandle, const wchar_t *matchPattern, int startIndex);` |
| `GetString` | method | `BOOL CkStringArrayW_GetString(HCkStringArrayW cHandle, int index, const wchar_t *outStr); const wchar_t *CkStringArrayW_getString(HCkStringArrayW cHandle, int index);` |
| `GetStringLen` | method | `int CkStringArrayW_GetStringLen(HCkStringArrayW cHandle, int index);` |
| `InsertAt` | method | `void CkStringArrayW_InsertAt(HCkStringArrayW cHandle, int index, const wchar_t *str);` |
| `LastString` | method | `BOOL CkStringArrayW_LastString(HCkStringArrayW cHandle, const wchar_t *outStr); const wchar_t *CkStringArrayW_lastString(HCkStringArrayW cHandle);` |
| `LoadFromFile` | method | `BOOL CkStringArrayW_LoadFromFile(HCkStringArrayW cHandle, const wchar_t *path);` |
| `LoadFromFile2` | method | `BOOL CkStringArrayW_LoadFromFile2(HCkStringArrayW cHandle, const wchar_t *path, const wchar_t *charset);` |
| `LoadFromText` | method | `void CkStringArrayW_LoadFromText(HCkStringArrayW cHandle, const wchar_t *str);` |
| `LoadTaskResult` | method | `BOOL CkStringArrayW_LoadTaskResult(HCkStringArrayW cHandle, HCkTaskW task);` |
| `Pop` | method | `BOOL CkStringArrayW_Pop(HCkStringArrayW cHandle, const wchar_t *outStr); const wchar_t *CkStringArrayW_pop(HCkStringArrayW cHandle);` |
| `Prepend` | method | `void CkStringArrayW_Prepend(HCkStringArrayW cHandle, const wchar_t *str);` |
| `Remove` | method | `void CkStringArrayW_Remove(HCkStringArrayW cHandle, const wchar_t *str);` |
| `RemoveAt` | method | `BOOL CkStringArrayW_RemoveAt(HCkStringArrayW cHandle, int index);` |
| `ReplaceAt` | method | `void CkStringArrayW_ReplaceAt(HCkStringArrayW cHandle, int index, const wchar_t *str);` |
| `SaveNthToFile` | method | `BOOL CkStringArrayW_SaveNthToFile(HCkStringArrayW cHandle, int index, const wchar_t *saveToPath);` |
| `SaveToFile` | method | `BOOL CkStringArrayW_SaveToFile(HCkStringArrayW cHandle, const wchar_t *path);` |
| `SaveToFile2` | method | `BOOL CkStringArrayW_SaveToFile2(HCkStringArrayW cHandle, const wchar_t *saveToPath, const wchar_t *charset);` |
| `SaveToText` | method | `BOOL CkStringArrayW_SaveToText(HCkStringArrayW cHandle, const wchar_t *outStr); const wchar_t *CkStringArrayW_saveToText(HCkStringArrayW cHandle);` |
| `Serialize` | method | `BOOL CkStringArrayW_Serialize(HCkStringArrayW cHandle, const wchar_t *outStr); const wchar_t *CkStringArrayW_serialize(HCkStringArrayW cHandle);` |
| `Sort` | method | `void CkStringArrayW_Sort(HCkStringArrayW cHandle, BOOL ascending);` |
| `SplitAndAppend` | method | `void CkStringArrayW_SplitAndAppend(HCkStringArrayW cHandle, const wchar_t *str, const wchar_t *boundary);` |
| `StrAt` | method | `BOOL CkStringArrayW_StrAt(HCkStringArrayW cHandle, int index, const wchar_t *outStr); const wchar_t *CkStringArrayW_strAt(HCkStringArrayW cHandle, int index);` |
| `Subtract` | method | `void CkStringArrayW_Subtract(HCkStringArrayW cHandle, HCkStringArrayW stringArrayObj);` |
| `Union` | method | `void CkStringArrayW_Union(HCkStringArrayW cHandle, HCkStringArrayW stringArrayObj);` |

## Properties

### StringArray.Count

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

```c
int CkStringArrayW_getCount(HCkStringArrayW cHandle);
```

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 · wc · StringArray · Crlf · property · read/write`

```c
BOOL CkStringArrayW_getCrlf(HCkStringArrayW cHandle);
void CkStringArrayW_putCrlf(HCkStringArrayW cHandle, BOOL newVal);
```

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 · wc · StringArray · Length · property · read-only`

```c
int CkStringArrayW_getLength(HCkStringArrayW cHandle);
```

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

### StringArray.Trim

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

```c
BOOL CkStringArrayW_getTrim(HCkStringArrayW cHandle);
void CkStringArrayW_putTrim(HCkStringArrayW cHandle, BOOL newVal);
```

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 · wc · StringArray · Unique · property · read/write`

```c
BOOL CkStringArrayW_getUnique(HCkStringArrayW cHandle);
void CkStringArrayW_putUnique(HCkStringArrayW cHandle, BOOL newVal);
```

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 · wc · StringArray · Append · method`

```c
BOOL CkStringArrayW_Append(HCkStringArrayW cHandle, const wchar_t *str);
```

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

Returns TRUE for success, FALSE for failure.

### StringArray.AppendSerialized

`Chilkat 11.7.0 · wc · StringArray · AppendSerialized · method`

```c
BOOL CkStringArrayW_AppendSerialized(HCkStringArrayW cHandle, const wchar_t *encodedStr);
```

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 · wc · StringArray · Clear · method`

```c
void CkStringArrayW_Clear(HCkStringArrayW cHandle);
```

Remove all strings from the internal collection.

### StringArray.Contains

`Chilkat 11.7.0 · wc · StringArray · Contains · method`

```c
BOOL CkStringArrayW_Contains(HCkStringArrayW cHandle, const wchar_t *str);
```

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

### StringArray.Find

`Chilkat 11.7.0 · wc · StringArray · Find · method`

```c
int CkStringArrayW_Find(HCkStringArrayW cHandle, const wchar_t *findStr, int startIndex);
```

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 · wc · StringArray · FindFirstMatch · method`

```c
int CkStringArrayW_FindFirstMatch(HCkStringArrayW cHandle, const wchar_t *matchPattern, int startIndex);
```

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 · wc · StringArray · GetString · method`

```c
BOOL CkStringArrayW_GetString(HCkStringArrayW cHandle, int index, const wchar_t *outStr);
const wchar_t *CkStringArrayW_getString(HCkStringArrayW cHandle, int index);
```

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 · wc · StringArray · GetStringLen · method`

```c
int CkStringArrayW_GetStringLen(HCkStringArrayW cHandle, int index);
```

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

### StringArray.InsertAt

`Chilkat 11.7.0 · wc · StringArray · InsertAt · method`

```c
void CkStringArrayW_InsertAt(HCkStringArrayW cHandle, int index, const wchar_t *str);
```

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 · wc · StringArray · LastString · method`

```c
BOOL CkStringArrayW_LastString(HCkStringArrayW cHandle, const wchar_t *outStr);
const wchar_t *CkStringArrayW_lastString(HCkStringArrayW cHandle);
```

Returns the last string in the internal collection.

Returns TRUE for success, FALSE for failure.

### StringArray.LoadFromFile

`Chilkat 11.7.0 · wc · StringArray · LoadFromFile · method`

```c
BOOL CkStringArrayW_LoadFromFile(HCkStringArrayW cHandle, const wchar_t *path);
```

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 · wc · StringArray · LoadFromFile2 · method`

```c
BOOL CkStringArrayW_LoadFromFile2(HCkStringArrayW cHandle, const wchar_t *path, const wchar_t *charset);
```

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 · wc · StringArray · LoadFromText · method`

```c
void CkStringArrayW_LoadFromText(HCkStringArrayW cHandle, const wchar_t *str);
```

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 · wc · StringArray · LoadTaskResult · method · since 9.5.0.52`

```c
BOOL CkStringArrayW_LoadTaskResult(HCkStringArrayW cHandle, HCkTaskW task);
```

Loads the string collection from a completed asynchronous task.

Returns TRUE for success, FALSE for failure.

### StringArray.Pop

`Chilkat 11.7.0 · wc · StringArray · Pop · method`

```c
BOOL CkStringArrayW_Pop(HCkStringArrayW cHandle, const wchar_t *outStr);
const wchar_t *CkStringArrayW_pop(HCkStringArrayW cHandle);
```

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

Returns TRUE for success, FALSE for failure.

### StringArray.Prepend

`Chilkat 11.7.0 · wc · StringArray · Prepend · method`

```c
void CkStringArrayW_Prepend(HCkStringArrayW cHandle, const wchar_t *str);
```

Adds a string to the beginning of the internal collection.

### StringArray.Remove

`Chilkat 11.7.0 · wc · StringArray · Remove · method`

```c
void CkStringArrayW_Remove(HCkStringArrayW cHandle, const wchar_t *str);
```

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

### StringArray.RemoveAt

`Chilkat 11.7.0 · wc · StringArray · RemoveAt · method`

```c
BOOL CkStringArrayW_RemoveAt(HCkStringArrayW cHandle, int index);
```

Removes the string at a particular index.

Returns TRUE for success, FALSE for failure.

### StringArray.ReplaceAt

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

```c
void CkStringArrayW_ReplaceAt(HCkStringArrayW cHandle, int index, const wchar_t *str);
```

Replaces the string at a specified index.

### StringArray.SaveNthToFile

`Chilkat 11.7.0 · wc · StringArray · SaveNthToFile · method`

```c
BOOL CkStringArrayW_SaveNthToFile(HCkStringArrayW cHandle, int index, const wchar_t *saveToPath);
```

Saves the Nth string in the collection to a file.

Returns TRUE for success, FALSE for failure.

### StringArray.SaveToFile

`Chilkat 11.7.0 · wc · StringArray · SaveToFile · method`

```c
BOOL CkStringArrayW_SaveToFile(HCkStringArrayW cHandle, const wchar_t *path);
```

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 · wc · StringArray · SaveToFile2 · method`

```c
BOOL CkStringArrayW_SaveToFile2(HCkStringArrayW cHandle, const wchar_t *saveToPath, const wchar_t *charset);
```

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 · wc · StringArray · SaveToText · method`

```c
BOOL CkStringArrayW_SaveToText(HCkStringArrayW cHandle, const wchar_t *outStr);
const wchar_t *CkStringArrayW_saveToText(HCkStringArrayW cHandle);
```

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 · wc · StringArray · Serialize · method`

```c
BOOL CkStringArrayW_Serialize(HCkStringArrayW cHandle, const wchar_t *outStr);
const wchar_t *CkStringArrayW_serialize(HCkStringArrayW cHandle);
```

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 · wc · StringArray · Sort · method`

```c
void CkStringArrayW_Sort(HCkStringArrayW cHandle, BOOL ascending);
```

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 · wc · StringArray · SplitAndAppend · method`

```c
void CkStringArrayW_SplitAndAppend(HCkStringArrayW cHandle, const wchar_t *str, const wchar_t *boundary);
```

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

### StringArray.StrAt

`Chilkat 11.7.0 · wc · StringArray · StrAt · method`

```c
BOOL CkStringArrayW_StrAt(HCkStringArrayW cHandle, int index, const wchar_t *outStr);
const wchar_t *CkStringArrayW_strAt(HCkStringArrayW cHandle, int index);
```

Returns the string at a specific index.

Returns TRUE for success, FALSE for failure.

### StringArray.Subtract

`Chilkat 11.7.0 · wc · StringArray · Subtract · method`

```c
void CkStringArrayW_Subtract(HCkStringArrayW cHandle, HCkStringArrayW stringArrayObj);
```

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

### StringArray.Union

`Chilkat 11.7.0 · wc · StringArray · Union · method`

```c
void CkStringArrayW_Union(HCkStringArrayW cHandle, HCkStringArrayW stringArrayObj);
```

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

## Related classes

[`Task`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/wc/classes/Task.md)

