CkStringBuilder class final

Build, transform, search, encode, decode, hash, and save mutable text.

CkStringBuilder is a flexible mutable text container for constructing and transforming strings. It supports appending text, integers, random values, UUIDs, encoded bytes, and BinData; searching, comparing, extracting, replacing, masking, regex processing, line-ending normalization, encoding, decoding, hashing, Markdown conversion, file I/O, and secure clearing of sensitive text.

Build text incrementally

Append strings, characters, integers, random values, UUIDs, encoded data, and other Chilkat objects without repeatedly recreating strings.

Search and extract

Find substrings, compare content, extract ranges, split or inspect text, and work with selected portions of the buffer.

Replace and transform

Replace text, mask sensitive values, normalize line endings, trim or edit content, and apply regex-based processing when needed.

Encoding and decoding

Encode or decode text and binary data using formats such as Base64, hex, URL encoding, quoted-printable, and other supported encodings.

Hashing and conversion

Compute hashes of the current text, convert Markdown to HTML, and move content between StringBuilder, BinData, files, and plain strings.

File I/O and secure clearing

Load text from files, save text with explicit character encodings, and securely clear the buffer when it contains sensitive data.

Common pattern: Use StringBuilder when text will be assembled or modified in multiple steps. Append or load the starting content, perform searches, replacements, encoding, decoding, hashing, or line-ending normalization, then retrieve the result as a string, save it to a file, or pass the object directly to another Chilkat method.

For an extended overview, see StringBuilder Class Overview.

A CkStringBuilder owns a native Chilkat object. It is released automatically when the Dart object is garbage collected, or immediately by dispose. Use it only from the isolate that created it.

Implemented types

Constructors

CkStringBuilder()
Creates a new CkStringBuilder object.

Properties

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.
getter/setter pair
hasEmojis → bool
Returns true if the content contains one or more emoji characters.
no setter
hashCode → int
The hash code for this object.
no setterinherited
intValue ↔ int
Returns the content of the string converted to an integer.
getter/setter pair
isBase64 → bool
Returns true if the content contains only those characters allowed in the base64 encoding. A base64 string is composed of characters 'A'..'Z', 'a'..'z', '0'..'9', '+', '/' and it is often padded at the end with up to two '=', to make the length a multiple of 4. Whitespace is ignored.
no setter
isDisposed → bool
Whether dispose has been called on this object.
no setter
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.
no setter
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.
no setter
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.
no setter
lastMethodSuccess ↔ bool
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.
getter/setter pair
length → int
The number of characters of the string contained within this instance.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
verboseLogging ↔ bool
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.
getter/setter pair
version → String
Version of the component/library, such as "10.1.0"
no setter

Methods

append(String value) → void
Appends a copy of the specified string to this instance.
appendBd(CkBinData binData, String charset, int offset, int numBytes) → void
Appends the contents of binData. The charset specifies the character encoding of the bytes contained in binData. The charset can be any of the supported encodings listed at Chilkat Supported Character Encodings. To append the entire contents of binData, set offset and numBytes equal to zero. To append a range of binData, set the offset and numBytes to specify the range.
appendInt(int value) → void
Appends the string representation of a specified 32-bit signed integer to this instance.
appendInt64(int value) → void
Appends the string representation of a specified 64-bit signed integer to this instance.
appendLine(String str, bool crlf) → void
Appends the str followed by a CRLF or LF to the end of the curent StringBuilder object. If crlf is true, then a CRLF line ending is used. Otherwise a LF line ending is used.
appendLn(String str) → void
Appends the str followed by a CRLF to the end of this object. This method is the same as appendLine, except the line-ending is always CRLF.
appendRandom(int numBytes, String encoding) → void
Append numBytes random bytes encoded according to encoding. encoding can be hex, hex_lower, base64, base64url, or any other encoding supported by Chilkat.
appendSb(CkStringBuilder sb) → void
Appends the contents of another StringBuilder to this instance.
appendUuid(bool lowerCase) → void
Generates and appends a random GUID/UUID such as 63c35f38-2b5f-4600-b3da-3ddee86d62b3. If lowerCase is true, then the hex values use lowercase (a - f). If lowerCase is false then uppercase is used (A - F).
appendUuid7(bool lowerCase) → void
Generates and appends a random version 7 UUID. If lowerCase is true, then the hex values use lowercase (a - f). If lowerCase is false then uppercase is used (A - F).
clear() → void
Removes all characters from the current StringBuilder instance.
contains(String str, bool caseSensitive) → bool
Returns true if the str is contained within this object. For case sensitive matching, set caseSensitive equal to true. For case-insensitive, set caseSensitive equal to false.
containsWord(String word, bool caseSensitive) → bool
Returns true if the word is contained within this object, but only if it is a whole word. This method is limited to finding whole words in strings that only contains characters in the Latin1 charset (i.e. iso-8859-1 or Windows-1252). A whole word can only contain alphanumeric chars where the alpha chars are restricted to those of the Latin1 alpha chars. (The underscore character is also considered part of a word.)
contentsEqual(String str, bool caseSensitive) → bool
Returns true if the contents of this object equals the str. Returns false if unequal. For case insensitive equality, set caseSensitive equal to false.
contentsEqualSb(CkStringBuilder sb, bool caseSensitive) → bool
Returns true if the contents of this object equals the sb. Returns false if unequal. For case insensitive equality, set caseSensitive equal to false.
decode(String encoding, String charset) → void
Decodes and replaces the contents with the decoded string. The encoding can be set to any of the following strings: base64, hex, quoted-printable (or qp), url, base32, Q, B, url_rc1738, url_rfc2396, url_rfc3986, url_oauth, uu, modBase64, or html (for HTML entity encoding). The full up-to-date list of supported binary encodings is available at the link entitled Supported Binary Encodings below.
decodeAndAppend(String value, String encoding, String charset) → void
Decodes a binary encoded string, where the binary encoding (such as url, hex, base64, etc.) is specified by encoding, and the underlying charset encoding (such as utf-8, windows-1252, etc.) is specified by charset. The decoded string is appended to this object.
dispose() → void
Releases the native object now instead of waiting for garbage collection.
encode(String encoding, String charset) → void
Encodes to base64, hex, quoted-printable, URL encoding, etc. The encoding can be set to any of the following strings: base64, hex, quoted-printable (or qp), url, base32, Q, B, url_rc1738, url_rfc2396, url_rfc3986, url_oauth, uu, modBase64, or html (for HTML entity encoding). The full up-to-date list of supported binary encodings is available at the link entitled Supported Binary Encodings below.
endsWith(String substr, bool caseSensitive) → bool
Returns true if the string ends with substr. Otherwise returns false. The comparison is case sensitive if caseSensitive is true, and case insensitive if caseSensitive is false.
entityDecode() → void
Decodes HTML entities. See HTML entities for more information about HTML entities.
getAfterBetween(String searchAfter, String beginMark, String endMark) → String
Begin searching after the 1st occurrence of searchAfter is found, and then return the substring found between the next occurrence of beginMark and the next occurrence of endMark.
getAfterFinal(String marker, bool removeFlag) → String
Returns the substring found after the final occurrence of marker. If removeFlag is true, the marker and the content that follows is removed from this content.
getAsString() → String
Returns the contents as a string.
getBefore(String marker, bool removeFlag) → String
Returns the substring found before the 1st occurrence of marker. If removeFlag is true, the content up to and including the marker is removed from this object's contents.
getBetween(String beginMark, String endMark) → String
Returns the substring found between the 1st occurrence of beginMark and the next occurrence of endMark.
getEncoded(String encoding, String charset) → String
Returns the string contents encoded in an encoding such as base64, hex, quoted-printable, or URL-encoding. The encoding can be set to any of the following strings: base64, hex, quoted-printable (or qp), url, base32, Q, B, url_rc1738, url_rfc2396, url_rfc3986, url_oauth, uu, modBase64, or html (for HTML entity encoding). The full up-to-date list of supported binary encodings is available at the link entitled Supported Binary Encodings below.
getHash(String algorithm, String encoding, String charset) → String
Returns the hash of the contents of this object. The algorithm is the hash algorithm, and can be sha1, sha256, sha384, sha512, sha3-224, sha3-256, sha3-384, sha3-512, md2, md5, ripemd128, ripemd160,ripemd256, or ripemd320. The encoding can be base64, modBase64, base64Url, base32, base58, qp (for quoted-printable), url (for url-encoding), hex, hexLower, or any of the encodings found at Chilkat Binary Encodings List.
getNth(int index, String delimiterChar, bool exceptDoubleQuoted, bool exceptEscaped) → String
Returns the Nth substring in string that is a list delimted by delimiterChar. The first substring is at index 0. If exceptDoubleQuoted is true, then the delimiter char found between double quotes is not treated as a delimiter. If exceptEscaped is true, then an escaped (with a backslash) delimiter char is not treated as a delimiter.
getRange(int startIndex, int numChars, bool removeFlag) → String
Returns a string containing the specified range of characters from this instance. If removeFlag is true, then the range of chars is removed from this instance.
getRangeSb(int startIndex, int numChars, bool removeFlag, CkStringBuilder sb) → void
Appends to startIndex the specified range of characters from this instance. If removeFlag is true, then the range of chars is removed from this instance.
htmlToMarkdown() → void
Converts the HTML contained in this object to Markdown, replacing the contents with the Markdown. Returns true on success. If the conversion fails, the contents are left unchanged and the reason is in the LastErrorText.
isWellFormed(String format) → bool
Returns true if the contents of this object are well-formed JSON or XML. format selects which check to apply and must be json or xml (case insensitive). Returns false if the contents do not conform, or if format is anything else.
lastNLines(int numLines, bool bCrlf) → String
Returns the last N lines of the text. If fewer than numLines lines exists, then all of the text is returned. If bCrlf is true, then the line endings of the returned string are converted to CRLF, otherwise the line endings are converted to LF-only.
loadFile(String path, String charset) → void
Loads the contents of a file.
markdownToHtml(CkJsonObject options, CkStringBuilder sbHtml) → void
This method converts the Markdown content of this object to HTML, storing the result in sbHtml. It supports both streaming and full document conversion. options specifies conversion options, including a key streaming option. In streaming mode, generated HTML is appended to sbHtml. In non-streaming mode, sbHtml is fully replaced by the generated HTML. For further details, see the examples linked below.
maskQuotedStrings(String maskChar, int quoteType, CkStringTable maskedStrings) → void
This function masks the content inside single and/or double-quoted strings by replacing it with a specified mask character (maskChar). The content of each masked quoted string is saved to maskedStrings. The contents can be restored by calling RestoreMaskedStrings.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
obfuscate() → void
Obfuscates the string. (The Unobfuscate method can be called to reverse the obfuscation to restore the original string.)
prepend(String value) → void
Prepends a copy of the specified string to this instance.
punyDecode() → void
In-place decodes the string from punycode.
punyEncode() → void
In-place encodes the string to punycode.
regexMatch(String pattern, CkJsonObject json, int timeoutMs) → int
Searches the content of this object for substrings that match a regular expression pattern and returns the matches in json. Returns the number of matches or -1 for failure. timeoutMs is the maximum number of milliseconds of processing allowed before giving up. Pass 0 for an infinite amount of time. Failure information is also returned in json.
regexReplace(CkJsonObject json) → void
Replaces the substrings of capture groups found in a previous call to RegexMatch.
removeAccents() → void
Removes the accents (diacritics) from European accented characters. This applies only to the accented characters found in the Windows-1252 (Latin alphabet) and Windows-1250 (Central European) charsets. Accent marks for characters in other languages will not be removed.
removeAfterFinal(String marker) → void
Removes the substring found after the final occurrence of the marker. Also removes the marker. Returns true if the marker was found and content was removed. Otherwise returns false.
removeBefore(String marker) → void
Removes the substring found before the 1st occurrence of the marker. Also removes the marker. Returns true if the marker was found and content was removed. Otherwise returns false.
removeCharsAt(int startIndex, int numChars) → void
Removes the specified range of characters from this instance.
removeEmojis() → void
Removes all emoji characters from the string.
replace(String value, String replacement) → int
Replaces all occurrences of a specified string in this instance with another specified string. Returns the number of replacements.
replaceAfterFinal(String marker, String replacement) → void
Replaces the content found after the final occurrence of marker with replacement.
replaceAllBetween(String beginMark, String endMark, String replacement, bool replaceMarks) → void
Replaces the first occurrence of ALL the content found between beginMark and endMark with replacement. The beginMark and endMark are included in what is replaced if replaceMarks is true.
replaceBetween(String beginMark, String endMark, String value, String replacement) → int
Replaces all occurrences of value with replacement, but only where value is found between beginMark and endMark. Returns the number of replacements made.
replaceFirst(String value, String replacement) → void
Replaces the first occurrence of a specified string in this instance with another string. Returns true if the value was found and replaced. Otherwise returns false.
replaceI(String value, int replacement) → int
Replaces all occurrences of value with the decimal integer replacement. Returns the number of replacements.
replaceNoCase(String value, String replacement) → int
Replaces all occurrences of value with replacement (case insensitive). Returns the number of replacements.
replaceWord(String value, String replacement) → int
Replaces all word occurrences of a specified string in this instance with another specified string. Returns the number of replacements made.
restoreMaskedStrings(int quoteType, CkStringTable maskedStrings) → void
Restores single and/or double-quoted strings previously masked by MaskQuotedStrings.
secureClear() → void
Removes all characters from the current StringBuilder instance, and write zero bytes to the allocated memory before deallocating.
setNth(int index, String value, String delimiterChar, bool exceptDoubleQuoted, bool exceptEscaped) → void
Sets the Nth substring in string in a list delimted by delimiterChar. The first substring is at index 0. If exceptDoubleQuoted is true, then the delimiter char found between double quotes is not treated as a delimiter. If exceptEscaped is true, then an escaped (with a backslash) delimiter char is not treated as a delimiter.
setString(String value) → void
Sets this instance to a copy of the specified string.
shorten(int numChars) → void
Shortens the string by removing the last numChars chars.
startsWith(String substr, bool caseSensitive) → bool
Returns true if the string starts with substr. Otherwise returns false. The comparison is case sensitive if caseSensitive is true, and case insensitive if caseSensitive is false.
toCRLF() → void
Converts line endings to CRLF (Windows) format.
toLF() → void
Converts line endings to LF-only (UNIX) format.
toLowercase() → void
Converts the contents to lowercase.
toString() → String
A string representation of this object.
override
toUppercase() → void
Converts the contents to uppercase.
trim() → void
Trims whitespace from both ends of the string.
trimInsideSpaces() → void
Replaces all tabs, CR's, and LF's, with SPACE chars, and removes extra SPACE's so there are no occurances of more than one SPACE char in a row.
unobfuscate() → void
Unobfuscates the string.
writeFile(String path, String charset, bool emitBom) → void
Writes the contents to a file. If emitBom is true, then the BOM (also known as a preamble), is emitted for charsets that define a BOM (such as utf-8, utf-16, utf-32, etc.)
writeFileIfModified(String path, String charset, bool emitBom) → void
Writes the contents to a file, but only if it is a new file or if the contents are different than the existing file. If emitBom is true, then the BOM (also known as a preamble), is emitted for charsets that define a BOM (such as utf-8, utf-16, utf-32, etc.)

Operators

operator ==(Object other) → bool
The equality operator.
inherited