StringArray React Native Reference Documentation
StringArray
Current Version: 11.6.1
Chilkat.StringArray
Store strings in an internal ordered collection and retrieve them by
zero-based index using
Append, prepend, insert, replace, remove, clear, or pop strings as the
collection changes.
Load one string per line from files or text, and save the collection back
to files or a single line-delimited string.
Use charset-specific load and save methods when working with UTF-8,
UTF-16, or other non-ANSI text encodings.
Check for exact strings, find values from a starting index, match
wildcard patterns, and sort ascending or descending.
Serialize the collection for later restoration, split text into entries,
and combine or subtract collections with set-style operations.
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.
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
GetString, StrAt, or
LastString.
Add and modify entries
Load and save text
Charset-aware file I/O
Search, match, and sort
Serialize and combine
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.
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
// npm install @chilkat/react-native react-native-nitro-modules
// (React Native 0.76+ with the New Architecture; then `pod install` for iOS. The Chilkat
// native library is downloaded and verified during the native build -- see the package README.)
import { Chilkat, StringArray } from '@chilkat/react-native'
// Once per app start, before any other Chilkat call:
Chilkat.unlockBundle('Anything for 30-day trial') // shorthand for new Global().unlockBundle(..)
const stringArray = new StringArray()
// ... the native object is released when `stringArray` is garbage collected, or now with stringArray.dispose()Creates the underlying native Chilkat object. StringArray is a Nitro Module HybridObject: use it from the JavaScript thread only (it cannot be passed to a Worklet or another runtime). Every member is synchronous and blocks the JavaScript thread until Chilkat returns; a method that can take a while also exists as a ...Async twin returning a Promise, which runs the same call on a native worker thread so the UI keeps rendering. While such a call is pending, every other call on this object throws, except abort() and assigning onPercentDone / onProgressInfo.
Releases the native object immediately instead of waiting for garbage collection (useful for a large BinData or an open socket). Calling it more than once is harmless; any other use of the object afterwards throws. An object with a pending ...Async call cannot be disposed until the promise settles.
Errors
A method that can fail throws a plain Error: a method whose only outcome is success or failure returns void and throws on failure; a method producing a string or an object returns it and throws where Chilkat would have returned null. The error's message is "Class.method(...): reason", where the reason is the last informative line of the object's lastErrorText, which holds the full Chilkat log of the failed call. A ...Async twin rejects its promise with the same Error instead of throwing. Properties never throw, and methods that answer a question (has..., is..., ...) return a plain boolean.
try {
stringArray.someMethod(...)
} catch (e) {
console.log((e as Error).message) // StringArray.someMethod(...): <reason>
console.log(stringArray.lastErrorText) // the full Chilkat log of the failed call
}
// The same call without blocking the JavaScript thread:
try {
await stringArray.someMethodAsync(...)
} catch (e) {
console.log((e as Error).message) // StringArray.someMethodAsync: <reason>
}
Properties
Count
readonly count: number
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.
Crlf
crlf: boolean
If true, strings are always automatically converted to use CRLF line endings. If false, strings are automatically converted to use bare LF line endings.
DebugLogFilePath
debugLogFilePath: string
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
LastErrorHtml
readonly lastErrorHtml: string
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
readonly lastErrorText: string
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
readonly lastErrorXml: string
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
lastMethodSuccess: boolean
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
Length
readonly length: number
The number of strings contained within the internal collection. (Identical to the Count property.)
topTrim
trim: boolean
If true, whitespace, including carriage-returns and linefeeds, are automatically removed from the beginning and end of a string when added to the collection.
Unique
unique: boolean
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.
VerboseLogging
verboseLogging: boolean
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
readonly version: string
Methods
Append
Appends a string to the end of the internal ordered collection.
Returns normally on success; throws an Error on failure.
AppendSerialized
Appends multiple strings to the end of the internal ordered collection. The encodedStr is what is returned from the Serialize method (see below).
Returns normally on success; throws an Error on failure.
Clear
Remove all strings from the internal collection.
topContains
Returns true if the string is present in the internal collection. The string comparisons are case sensitive.
Find
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.
FindFirstMatch
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.
GetString
Returns the string at an indexed location within the internal collection. The first string is located at index 0.
Throws an Error on failure (where the description says null is returned, the method throws instead).
GetStringLen
Returns Nth string's length, in characters. The first string is located at index 0.
topInsertAt
Inserts a string into the internal collection at a specified index. Using index 0 will insert at the beginning.
topLastString
Returns the last string in the internal collection.
Throws an Error on failure (where the description says null is returned, the method throws instead).
LoadFromFile
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 normally on success; throws an Error on failure.
LoadFromFile2
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 normally on success; throws an Error on failure.
LoadFromText
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.
Pop
Returns the last string and removes it from the internal collection.
Throws an Error on failure (where the description says null is returned, the method throws instead).
Prepend
Adds a string to the beginning of the internal collection.
topRemove
Removes all strings equal to the string argument from the internal collection.
topRemoveAt
Removes the string at a particular index.
Returns normally on success; throws an Error on failure.
ReplaceAt
Replaces the string at a specified index.
topSaveNthToFile
Saves the Nth string in the collection to a file.
Returns normally on success; throws an Error on failure.
SaveToFile
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 normally on success; throws an Error on failure.
SaveToFile2
Saves the collection of strings to a file, one string per line. Strings are saved using the specified charset.
Returns normally on success; throws an Error on failure.
SaveToText
Writes the collection of strings to a single string, one per line (separated by CRLF line endings).
Throws an Error on failure (where the description says null is returned, the method throws instead).
Serialize
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.
Throws an Error on failure (where the description says null is returned, the method throws instead).
Sort
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.
SplitAndAppend
Splits a string at a character or substring boundary and adds each resulting string to the internal collection.
topStrAt
Returns the string at a specific index.
Throws an Error on failure (where the description says null is returned, the method throws instead).
Subtract
Subtracts the strings contained within stringArrayObj from the caller's internal collection.
Union
Performs the union set-operator. The result is that the caller will have a string collection that is the union of itself and stringArrayObj.