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
CkStringBuilderobject.
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
trueif 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
trueif 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:
truemeans success,falsemeans 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 isfalse. 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. Thecharsetspecifies the character encoding of the bytes contained inbinData. Thecharsetcan be any of the supported encodings listed at Chilkat Supported Character Encodings. To append the entire contents ofbinData, setoffsetandnumBytesequal to zero. To append a range ofbinData, set theoffsetandnumBytesto 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
strfollowed by a CRLF or LF to the end of the curent StringBuilder object. Ifcrlfistrue, then a CRLF line ending is used. Otherwise a LF line ending is used. -
appendLn(
String str) → void -
Appends the
strfollowed 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
numBytesrandom bytes encoded according toencoding.encodingcan behex,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
lowerCaseistrue, then the hex values use lowercase (a-f). IflowerCaseisfalsethen uppercase is used (A-F). -
appendUuid7(
bool lowerCase) → void -
Generates and appends a random version 7 UUID. If
lowerCaseistrue, then the hex values use lowercase (a-f). IflowerCaseisfalsethen uppercase is used (A-F). -
clear(
) → void - Removes all characters from the current StringBuilder instance.
-
contains(
String str, bool caseSensitive) → bool -
Returns
trueif thestris contained within this object. For case sensitive matching, setcaseSensitiveequal totrue. For case-insensitive, setcaseSensitiveequal tofalse. -
containsWord(
String word, bool caseSensitive) → bool -
Returns
trueif thewordis 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
trueif the contents of this object equals thestr. Returnsfalseif unequal. For case insensitive equality, setcaseSensitiveequal tofalse. -
contentsEqualSb(
CkStringBuilder sb, bool caseSensitive) → bool -
Returns
trueif the contents of this object equals thesb. Returnsfalseif unequal. For case insensitive equality, setcaseSensitiveequal tofalse. -
decode(
String encoding, String charset) → void -
Decodes and replaces the contents with the decoded string. The
encodingcan be set to any of the following strings:base64,hex,quoted-printable(orqp),url,base32,Q,B,url_rc1738,url_rfc2396,url_rfc3986,url_oauth,uu,modBase64, orhtml(for HTML entity encoding). The full up-to-date list of supported binary encodings is available at the link entitledSupported Binary Encodingsbelow. -
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 byencoding, and the underlying charset encoding (such asutf-8,windows-1252, etc.) is specified bycharset. 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
encodingcan be set to any of the following strings:base64,hex,quoted-printable(orqp),url,base32,Q,B,url_rc1738,url_rfc2396,url_rfc3986,url_oauth,uu,modBase64, orhtml(for HTML entity encoding). The full up-to-date list of supported binary encodings is available at the link entitledSupported Binary Encodingsbelow. -
endsWith(
String substr, bool caseSensitive) → bool -
Returns
trueif the string ends withsubstr. Otherwise returnsfalse. The comparison is case sensitive ifcaseSensitiveistrue, and case insensitive ifcaseSensitiveisfalse. -
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
searchAfteris found, and then return the substring found between the next occurrence ofbeginMarkand the next occurrence ofendMark. -
getAfterFinal(
String marker, bool removeFlag) → String -
Returns the substring found after the final occurrence of
marker. IfremoveFlagistrue, themarkerand 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. IfremoveFlagistrue, the content up to and including themarkeris removed from this object's contents. -
getBetween(
String beginMark, String endMark) → String -
Returns the substring found between the 1st occurrence of
beginMarkand the next occurrence ofendMark. -
getEncoded(
String encoding, String charset) → String -
Returns the string contents encoded in an encoding such as base64, hex,
quoted-printable, or URL-encoding. The
encodingcan be set to any of the following strings:base64,hex,quoted-printable(orqp),url,base32,Q,B,url_rc1738,url_rfc2396,url_rfc3986,url_oauth,uu,modBase64, orhtml(for HTML entity encoding). The full up-to-date list of supported binary encodings is available at the link entitledSupported Binary Encodingsbelow. -
getHash(
String algorithm, String encoding, String charset) → String -
Returns the hash of the contents of this object. The
algorithmis the hash algorithm, and can besha1,sha256,sha384,sha512,sha3-224,sha3-256,sha3-384,sha3-512,md2,md5,ripemd128,ripemd160,ripemd256, orripemd320. Theencodingcan bebase64,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. IfexceptDoubleQuotedistrue, then the delimiter char found between double quotes is not treated as a delimiter. IfexceptEscapedistrue, 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
removeFlagistrue, then the range of chars is removed from this instance. -
getRangeSb(
int startIndex, int numChars, bool removeFlag, CkStringBuilder sb) → void -
Appends to
startIndexthe specified range of characters from this instance. IfremoveFlagistrue, 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
trueon success. If the conversion fails, the contents are left unchanged and the reason is in the LastErrorText. -
isWellFormed(
String format) → bool -
Returns
trueif the contents of this object are well-formed JSON or XML.formatselects which check to apply and must bejsonorxml(case insensitive). Returnsfalseif the contents do not conform, or ifformatis anything else. -
lastNLines(
int numLines, bool bCrlf) → String -
Returns the last N lines of the text. If fewer than
numLineslines exists, then all of the text is returned. IfbCrlfistrue, 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.optionsspecifies conversion options, including a keystreamingoption. Instreamingmode, generated HTML is appended tosbHtml. In non-streaming mode,sbHtmlis 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 tomaskedStrings. 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.timeoutMsis the maximum number of milliseconds of processing allowed before giving up. Pass 0 for an infinite amount of time. Failure information is also returned injson. -
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 themarker. Returnstrueif themarkerwas found and content was removed. Otherwise returnsfalse. -
removeBefore(
String marker) → void -
Removes the substring found before the 1st occurrence of the
marker. Also removes themarker. Returnstrueif themarkerwas found and content was removed. Otherwise returnsfalse. -
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
markerwithreplacement. -
replaceAllBetween(
String beginMark, String endMark, String replacement, bool replaceMarks) → void -
Replaces the first occurrence of ALL the content found between
beginMarkandendMarkwithreplacement. ThebeginMarkandendMarkare included in what is replaced ifreplaceMarksistrue. -
replaceBetween(
String beginMark, String endMark, String value, String replacement) → int -
Replaces all occurrences of
valuewithreplacement, but only wherevalueis found betweenbeginMarkandendMark. 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
trueif thevaluewas found and replaced. Otherwise returnsfalse. -
replaceI(
String value, int replacement) → int -
Replaces all occurrences of
valuewith the decimal integerreplacement. Returns the number of replacements. -
replaceNoCase(
String value, String replacement) → int -
Replaces all occurrences of
valuewithreplacement(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. IfexceptDoubleQuotedistrue, then the delimiter char found between double quotes is not treated as a delimiter. IfexceptEscapedistrue, 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
numCharschars. -
startsWith(
String substr, bool caseSensitive) → bool -
Returns
trueif the string starts withsubstr. Otherwise returnsfalse. The comparison is case sensitive ifcaseSensitiveistrue, and case insensitive ifcaseSensitiveisfalse. -
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
emitBomistrue, 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
emitBomistrue, 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