Class StringBuilder
- All Implemented Interfaces:
AutoCloseable
Build, transform, search, encode, decode, hash, and save mutable text.
Chilkat.StringBuilder 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.
</section>
Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when
done; an unclosed instance is freed when it becomes unreachable.
- See Also:
- Online reference
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAppends a copy of the specified string to this instance.voidAppends the contents ofbinData.voidappendInt(int value)Appends the string representation of a specified 32-bit signed integer to this instance.voidappendInt64(long value)Appends the string representation of a specified 64-bit signed integer to this instance.voidappendLine(String str, boolean crlf)Appends thestrfollowed by a CRLF or LF to the end of the curent StringBuilder object.voidAppends thestrfollowed by a CRLF to the end of this object.voidappendRandom(int numBytes, String encoding)AppendnumBytesrandom bytes encoded according toencoding.voidappendSb(StringBuilder sb)Appends the contents of another StringBuilder to this instance.voidappendUuid(boolean lowerCase)Generates and appends a random GUID/UUID such as 63c35f38-2b5f-4600-b3da-3ddee86d62b3.voidappendUuid7(boolean lowerCase)Generates and appends a random version 7 UUID.voidclear()Removes all characters from the current StringBuilder instance.booleanReturnstrueif thestris contained within this object.booleancontainsWord(String word, boolean caseSensitive)Returnstrueif thewordis contained within this object, but only if it is a whole word.booleancontentsEqual(String str, boolean caseSensitive)Returnstrueif the contents of this object equals thestr.booleancontentsEqualSb(StringBuilder sb, boolean caseSensitive)Returnstrueif the contents of this object equals thesb.voidDecodes and replaces the contents with the decoded string.voiddecodeAndAppend(String value, String encoding, String charset)Decodes a binary encoded string, where the binary encoding (such asurl,hex,base64, etc.) is specified byencoding, and the underlying charset encoding (such asutf-8,windows-1252, etc.) is specified bycharset.voidEncodes to base64, hex, quoted-printable, URL encoding, etc.booleanReturnstrueif the string ends withsubstr.voidDecodes HTML entities.getAfterBetween(String searchAfter, String beginMark, String endMark)Begin searching after the 1st occurrence ofsearchAfteris found, and then return the substring found between the next occurrence ofbeginMarkand the next occurrence ofendMark.getAfterFinal(String marker, boolean removeFlag)Returns the substring found after the final occurrence ofmarker.Returns the contents as a string.Returns the substring found before the 1st occurrence ofmarker.getBetween(String beginMark, String endMark)Returns the substring found between the 1st occurrence ofbeginMarkand the next occurrence ofendMark.getEncoded(String encoding, String charset)Returns the string contents encoded in an encoding such as base64, hex, quoted-printable, or URL-encoding.booleanReturnstrueif the content contains one or more emoji characters.Returns the hash of the contents of this object.intReturns the content of the string converted to an integer.booleanReturnstrueif the content contains only those characters allowed in the base64 encoding.intThe number of characters of the string contained within this instance.Returns the Nth substring in string that is a list delimted bydelimiterChar.getRange(int startIndex, int numChars, boolean removeFlag)Returns a string containing the specified range of characters from this instance.voidgetRangeSb(int startIndex, int numChars, boolean removeFlag, StringBuilder sb)Appends tostartIndexthe specified range of characters from this instance.voidConverts the HTML contained in this object to Markdown, replacing the contents with the Markdown.booleanisWellFormed(String format)Returnstrueif the contents of this object are well-formed JSON or XML.lastNLines(int numLines, boolean bCrlf)Returns the last N lines of the text.voidLoads the contents of a file.voidmarkdownToHtml(JsonObject options, StringBuilder sbHtml)This method converts the Markdown content of this object to HTML, storing the result insbHtml.voidmaskQuotedStrings(String maskChar, int quoteType, StringTable maskedStrings)This function masks the content inside single and/or double-quoted strings by replacing it with a specified mask character (maskChar).voidObfuscates the string.voidPrepends a copy of the specified string to this instance.voidIn-place decodes the string from punycode.voidIn-place encodes the string to punycode.intregexMatch(String pattern, JsonObject json, int timeoutMs)Searches the content of this object for substrings that match a regular expression pattern and returns the matches injson.voidregexReplace(JsonObject json)Replaces the substrings of capture groups found in a previous call to RegexMatch.voidRemoves the accents (diacritics) from European accented characters.voidremoveAfterFinal(String marker)Removes the substring found after the final occurrence of themarker.voidremoveBefore(String marker)Removes the substring found before the 1st occurrence of themarker.voidremoveCharsAt(int startIndex, int numChars)Removes the specified range of characters from this instance.voidRemoves all emoji characters from the string.intReplaces all occurrences of a specified string in this instance with another specified string.voidreplaceAfterFinal(String marker, String replacement)Replaces the content found after the final occurrence ofmarkerwithreplacement.voidreplaceAllBetween(String beginMark, String endMark, String replacement, boolean replaceMarks)Replaces the first occurrence of ALL the content found betweenbeginMarkandendMarkwithreplacement.intreplaceBetween(String beginMark, String endMark, String value, String replacement)Replaces all occurrences ofvaluewithreplacement, but only wherevalueis found betweenbeginMarkandendMark.voidreplaceFirst(String value, String replacement)Replaces the first occurrence of a specified string in this instance with another string.intReplaces all occurrences ofvaluewith the decimal integerreplacement.intreplaceNoCase(String value, String replacement)Replaces all occurrences ofvaluewithreplacement(case insensitive).intreplaceWord(String value, String replacement)Replaces all word occurrences of a specified string in this instance with another specified string.voidrestoreMaskedStrings(int quoteType, StringTable maskedStrings)Restores single and/or double-quoted strings previously masked by MaskQuotedStrings.voidRemoves all characters from the current StringBuilder instance, and write zero bytes to the allocated memory before deallocating.voidsetIntValue(int value)Sets theIntValueproperty; seegetIntValue().voidsetNth(int index, String value, String delimiterChar, boolean exceptDoubleQuoted, boolean exceptEscaped)Sets the Nth substring in string in a list delimted bydelimiterChar.voidSets this instance to a copy of the specified string.voidshorten(int numChars)Shortens the string by removing the lastnumCharschars.booleanstartsWith(String substr, boolean caseSensitive)Returnstrueif the string starts withsubstr.voidtoCRLF()Converts line endings to CRLF (Windows) format.voidtoLF()Converts line endings to LF-only (UNIX) format.voidConverts the contents to lowercase.voidConverts the contents to uppercase.voidtrim()Trims whitespace from both ends of the string.voidReplaces 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.voidUnobfuscates the string.voidWrites the contents to a file.voidwriteFileIfModified(String path, String charset, boolean emitBom)Writes the contents to a file, but only if it is a new file or if the contents are different than the existing file.Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
StringBuilder
public StringBuilder()Creates a newStringBuilderobject.
-
-
Method Details
-
getHasEmojis
public boolean getHasEmojis()Returnstrueif the content contains one or more emoji characters.- Returns:
- the value of the
HasEmojisproperty (read-only)
-
getIntValue
public int getIntValue()Returns the content of the string converted to an integer.- Returns:
- the value of the
IntValueproperty
-
setIntValue
public void setIntValue(int value)Sets theIntValueproperty; seegetIntValue().- Parameters:
value- the new value
-
getIsBase64
public boolean getIsBase64()Returnstrueif 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.- Returns:
- the value of the
IsBase64property (read-only)
-
getLength
public int getLength()The number of characters of the string contained within this instance.- Returns:
- the value of the
Lengthproperty (read-only)
-
append
Appends a copy of the specified string to this instance.- Parameters:
value- thevalueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendBd
Appends the contents ofbinData. 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.- Parameters:
binData- thebinDataargument (notnull)charset- thecharsetargument (notnull)offset- theoffsetargumentnumBytes- thenumBytesargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendInt
public void appendInt(int value)Appends the string representation of a specified 32-bit signed integer to this instance.- Parameters:
value- thevalueargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendInt64
public void appendInt64(long value)Appends the string representation of a specified 64-bit signed integer to this instance.- Parameters:
value- thevalueargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendLine
Appends thestrfollowed 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.- Parameters:
str- thestrargument (notnull)crlf- thecrlfargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendLn
Appends thestrfollowed by a CRLF to the end of this object. This method is the same as, except the line-ending is always CRLF.appendLine(String, boolean)- Parameters:
str- thestrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendRandom
AppendnumBytesrandom bytes encoded according toencoding.encodingcan behex,hex_lower,base64,base64url, or any other encoding supported by Chilkat.- Parameters:
numBytes- thenumBytesargumentencoding- theencodingargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendSb
Appends the contents of another StringBuilder to this instance.- Parameters:
sb- thesbargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendUuid
public void appendUuid(boolean lowerCase)Generates and appends a random GUID/UUID such as 63c35f38-2b5f-4600-b3da-3ddee86d62b3. IflowerCaseistrue, then the hex values use lowercase (a-f). IflowerCaseisfalsethen uppercase is used (A-F).Note: This generates a version 4 UUID.
- Parameters:
lowerCase- thelowerCaseargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendUuid7
public void appendUuid7(boolean lowerCase)Generates and appends a random version 7 UUID. IflowerCaseistrue, then the hex values use lowercase (a-f). IflowerCaseisfalsethen uppercase is used (A-F).- Parameters:
lowerCase- thelowerCaseargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
clear
public void clear()Removes all characters from the current StringBuilder instance. -
contains
Returnstrueif thestris contained within this object. For case sensitive matching, setcaseSensitiveequal totrue. For case-insensitive, setcaseSensitiveequal tofalse.- Parameters:
str- thestrargument (notnull)caseSensitive- thecaseSensitiveargument- Returns:
- the result; this method never throws
ChilkatException
-
containsWord
Returnstrueif 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.)For case sensitive matching, set
caseSensitiveequal totrue. For case-insensitive, setcaseSensitiveequal tofalse.- Parameters:
word- thewordargument (notnull)caseSensitive- thecaseSensitiveargument- Returns:
- the result; this method never throws
ChilkatException
-
contentsEqual
Returnstrueif the contents of this object equals thestr. Returnsfalseif unequal. For case insensitive equality, setcaseSensitiveequal tofalse.- Parameters:
str- thestrargument (notnull)caseSensitive- thecaseSensitiveargument- Returns:
- the result; this method never throws
ChilkatException
-
contentsEqualSb
Returnstrueif the contents of this object equals thesb. Returnsfalseif unequal. For case insensitive equality, setcaseSensitiveequal tofalse.- Parameters:
sb- thesbargument (notnull)caseSensitive- thecaseSensitiveargument- Returns:
- the result; this method never throws
ChilkatException
-
decode
Decodes and replaces the contents with the decoded string. Theencodingcan 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.Note: This method can only be called if the encoded content decodes to a string. The
charsetindicates the charset to be used in intepreting the decoded bytes. For example, thecharsetcan beutf-8,utf-16,iso-8859-1,shift_JIS, etc.- Parameters:
encoding- theencodingargument (notnull)charset- thecharsetargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
decodeAndAppend
Decodes a binary encoded string, where the binary encoding (such asurl,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.- Parameters:
value- thevalueargument (notnull)encoding- theencodingargument (notnull)charset- thecharsetargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
encode
Encodes to base64, hex, quoted-printable, URL encoding, etc. Theencodingcan 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.- Parameters:
encoding- theencodingargument (notnull)charset- thecharsetargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
endsWith
Returnstrueif the string ends withsubstr. Otherwise returnsfalse. The comparison is case sensitive ifcaseSensitiveistrue, and case insensitive ifcaseSensitiveisfalse.- Parameters:
substr- thesubstrargument (notnull)caseSensitive- thecaseSensitiveargument- Returns:
- the result; this method never throws
ChilkatException
-
entityDecode
public void entityDecode()Decodes HTML entities. See HTML entities for more information about HTML entities.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getAfterBetween
Begin searching after the 1st occurrence ofsearchAfteris found, and then return the substring found between the next occurrence ofbeginMarkand the next occurrence ofendMark.- Parameters:
searchAfter- thesearchAfterargument (notnull)beginMark- thebeginMarkargument (notnull)endMark- theendMarkargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getAfterFinal
Returns the substring found after the final occurrence ofmarker. IfremoveFlagistrue, themarkerand the content that follows is removed from this content.If the
markeris not present, then the entire string is returned. In this case, ifremoveFlagistrue, this object is also cleared.- Parameters:
marker- themarkerargument (notnull)removeFlag- theremoveFlagargument- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getAsString
Returns the contents as a string.- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getBefore
Returns the substring found before the 1st occurrence ofmarker. IfremoveFlagistrue, the content up to and including themarkeris removed from this object's contents.If the
markeris not present, then the entire string is returned. In this case, ifremoveFlagistrue, this object is also cleared.- Parameters:
marker- themarkerargument (notnull)removeFlag- theremoveFlagargument- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getBetween
Returns the substring found between the 1st occurrence ofbeginMarkand the next occurrence ofendMark.- Parameters:
beginMark- thebeginMarkargument (notnull)endMark- theendMarkargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getEncoded
Returns the string contents encoded in an encoding such as base64, hex, quoted-printable, or URL-encoding. Theencodingcan 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.Note: The Encode method modifies the content of this object. The GetEncoded method leaves this object's content unmodified.
- Parameters:
encoding- theencodingargument (notnull)charset- thecharsetargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getHash
Returns the hash of the contents of this object. Thealgorithmis 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.The
charsetis the character encoding byte representation to hash. It is typicallyutf-8. It can be any of the chacter encodings listed at Chilkat Character Encodings List.- Parameters:
algorithm- thealgorithmargument (notnull)encoding- theencodingargument (notnull)charset- thecharsetargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getNth
public String getNth(int index, String delimiterChar, boolean exceptDoubleQuoted, boolean exceptEscaped)Returns the Nth substring in string that is a list delimted bydelimiterChar. 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.- Parameters:
index- theindexargumentdelimiterChar- thedelimiterCharargument (notnull)exceptDoubleQuoted- theexceptDoubleQuotedargumentexceptEscaped- theexceptEscapedargument- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getRange
Returns a string containing the specified range of characters from this instance. IfremoveFlagistrue, then the range of chars is removed from this instance.Note: It was discovered that the range of chars was always removed regardless of the value of
removeFlag. This is fixed in v9.5.0.89.- Parameters:
startIndex- thestartIndexargumentnumChars- thenumCharsargumentremoveFlag- theremoveFlagargument- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getRangeSb
Appends tostartIndexthe specified range of characters from this instance. IfremoveFlagistrue, then the range of chars is removed from this instance.- Parameters:
startIndex- thestartIndexargumentnumChars- thenumCharsargumentremoveFlag- theremoveFlagargumentsb- thesbargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
htmlToMarkdown
public void htmlToMarkdown()Converts the HTML contained in this object to Markdown, replacing the contents with the Markdown. Returnstrueon success. If the conversion fails, the contents are left unchanged and the reason is in the LastErrorText.This is the reverse of
. The HTML is parsed with the same parser used bymarkdownToHtml(JsonObject, StringBuilder)Html.ToXmlandHtml.ToText, and the resulting document tree produces CommonMark / GitHub-flavored Markdown:h1throughh6become#..######headings.p,div,sectionand other block-level elements become paragraphs separated by a blank line.brbecomes a hard line break andhrbecomes---.b/strongbecome**bold**,i/em/citebecome*italic*,del/s/strikebecome~~struck~~, andcode/kbd/sampbecome a backtick code span.prebecomes a fenced code block. The language is taken from alanguage-xxxorlang-xxxclass on thepreor itscodechild.a hrefbecomes[text](url "title"), andimgbecomes.ul/ol/libecome-and1.lists, with nested lists indented. A checkboxinputinside a list item becomes[ ]or[x].blockquotebecomes lines prefixed with>.tablebecomes a GitHub pipe table. The first row is the header when it containsthcells or is inside athead;colspanis honored, andalignortext-alignsets the column alignment. A single-column table becomes plain paragraphs, because such tables are usually for layout.dl/dt/ddbecome a term line followed by: definitionlines.
head,script,style,title,meta,link,noscript,iframe,object,embed,svg,canvas, form controls and comments produce no output. Any other tag is transparent: only its content is emitted.Markdown-significant punctuation in ordinary text is backslash-escaped so that the text renders literally. Text inside
codeandpreis never escaped. HTML entities are decoded.The Markdown uses LF line endings, always ends with a single line ending, and never contains more than one consecutive blank line outside of a code block. Call
afterwards for CRLF line endings.toCRLF()Note: The conversion is in-place. The HTML is not available after a successful call, so load it into a separate
StringBuilderfirst if it is still needed.Empty contents, or HTML with no visible content, produce empty contents and
trueis returned.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
isWellFormed
Returnstrueif 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.Chilkat's JSON and XML parsers are deliberately tolerant. Given text that is not well-formed they can still report success, leaving an empty or partially populated document. This method answers the question those parsers do not, and it does so without loading the text into a
JsonObjectorXmlobject first. The checks applied here are the same ones those classes apply when theirStrictproperty is set.For
xmlthis is a well-formedness check: element nesting and tag matching, attribute syntax and duplicate attributes, entity and character references, comments, processing instructions, CDATA sections, the XML declaration, the DOCTYPE declaration, and that the bytes are valid UTF-8 containing only characters XML permits. It is not a validating parse: no DTD or schema is read.For
jsonthe full RFC 8259 grammar is checked.Empty contents are not well-formed in either format, so
falseis returned.Note: The contents of this object are never modified by this method.
- Parameters:
format- theformatargument (notnull)- Returns:
- the result; this method never throws
ChilkatException
-
lastNLines
Returns the last N lines of the text. If fewer thannumLineslines 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.- Parameters:
numLines- thenumLinesargumentbCrlf- thebCrlfargument- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadFile
Loads the contents of a file.- Parameters:
path- thepathargument (notnull)charset- thecharsetargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
markdownToHtml
This method converts the Markdown content of this object to HTML, storing the result insbHtml. 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.In
streamingmode, only complete markdown lines are converted to HTML and removed from this object, leaving just the final partial line, if present. If this object contains only a partial markdown line, no HTML is emitted.Starting in
v11.3.0..."emitJavascript": truecan be included inoptionsto emit Javascript function calls instead of HTML. This is used to update the response in an embedded browser in real-time. See Real-Time Streaming AI Responses to Embedded Browsers in Desktop Apps"streamingShell": trueis used to convert an empty string to an HTML shell to be used as the starting point before applying Javascript function calls. See Preparing the HTML Shell"theme": "html_theme_name"can be included when creating the HTML shell to select a predefined theme or when converting Markdown to HTML in non-streaming mode. The available themes are:- ChatGPT - A style that is similar to the ChatGPT application.
- cleanWin - A clean style for Windows applications.
- cleanMac - A clean style for MacOS applications.
- raw - No HTML styles, header, or body begin/end elements are emitted. Only the Markdown to HTML
generated elements are emitted.
If no
themeis is included, then default HTML docType/root/body/header elements are emitted unless various parts are overridden bydocType,rootElement,head,bodyStart,bodyEnd, andbodyExtra."usesPrism": truecan be included when creating the HTML shell (or when converting Markdown to HTML in non-streaming mode) to include PRISM code highlighting."prism": { "theme": "prism_theme_name" }Is optional and can be used to specify the prism theme whenusesPrismistrue. Possible values are:- tomorrow
- default
- coy
- dark
- funky
- okaidia
- solarizedlight
- twilight
"prism": { "version": "version_number" }Is optional can can be used to specify the prism version, such as"1.29.0"whenusesPrismistrue. If not specified, then "1.29.0" is used.- If no
themeis specified, then any or all of the following HTML document parts can be explicitly specified:"docType": "doctype_element"TheDOCTYPEelement. The default is"_LT_!DOCTYPE html>""rootElement": "root_element"Thehtmlelement. The default is"_LT_html>""head": "head_section"The HTML fragment for the HTML head section. The default is"_LT_head>_LT_meta charset="utf-8" />_LT_/head>".
Note: IfusesPrismistrue, then prism related links will be inserted just before the_LT_/head>."bodyStart": "html_fragment"The HTML fragment to begin the body section. The default is"_LT_body>_LT_div id="content">""bodyEnd": "html_fragment"The HTML fragment to end the body section. The default is"_LT_/div>_LT_!-- end-of-content-div -->_LT_/body>""noContentDiv": trueIf set, the default bodyStart and bodyEnd do not include the"_LT_div id="content">"and"_LT_/div>_LT_!-- end-of-content-div -->"
"copyButton": trueIn non-streaming mode, can optionally be set to include HTML for adding a copy button. THe copy button is added by default in streaming mode."ChatGPT": { "max-width": "css_length"; }Is optional can can be used to specify the max width of the body text if thethemeisChatGPT. The css_length is a length using CSS length units, such as"72ch","40em","800px", etc.
- Parameters:
options- theoptionsargument (notnull)sbHtml- thesbHtmlargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
maskQuotedStrings
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.quoteTypedetermines which types of quoted strings are masked:- Both single and double quoted.
- Only single quoted strings.
- Only double quoted strings.
- Parameters:
maskChar- themaskCharargument (notnull)quoteType- thequoteTypeargumentmaskedStrings- themaskedStringsargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
obfuscate
public void obfuscate()Obfuscates the string. (The Unobfuscate method can be called to reverse the obfuscation to restore the original string.)The Chilkat string obfuscation algorithm works by taking the utf-8 bytes of the string, base64 encoding it, and then scrambling the letters of the base64 encoded string. It is deterministic in that the same string will always obfuscate to the same result. It is NOT a secure way of encrypting a string. It is only meant to be a simple means of transforming a string into something unintelligible.
-
prepend
Prepends a copy of the specified string to this instance.- Parameters:
value- thevalueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
punyDecode
public void punyDecode()In-place decodes the string from punycode.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
punyEncode
public void punyEncode()In-place encodes the string to punycode.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
regexMatch
Searches the content of this object for substrings that match a regular expression pattern and returns the matches injson. 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.- Parameters:
pattern- thepatternargument (notnull)json- thejsonargument (notnull)timeoutMs- thetimeoutMsargument- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
regexReplace
Replaces the substrings of capture groups found in a previous call to RegexMatch.- Parameters:
json- thejsonargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
removeAccents
public void removeAccents()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.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
removeAfterFinal
Removes the substring found after the final occurrence of themarker. Also removes themarker. Returnstrueif themarkerwas found and content was removed. Otherwise returnsfalse.- Parameters:
marker- themarkerargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
removeBefore
Removes the substring found before the 1st occurrence of themarker. Also removes themarker. Returnstrueif themarkerwas found and content was removed. Otherwise returnsfalse.- Parameters:
marker- themarkerargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
removeCharsAt
public void removeCharsAt(int startIndex, int numChars)Removes the specified range of characters from this instance.- Parameters:
startIndex- thestartIndexargumentnumChars- thenumCharsargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
removeEmojis
public void removeEmojis()Removes all emoji characters from the string. -
replace
Replaces all occurrences of a specified string in this instance with another specified string. Returns the number of replacements.- Parameters:
value- thevalueargument (notnull)replacement- thereplacementargument (notnull)- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
replaceAfterFinal
Replaces the content found after the final occurrence ofmarkerwithreplacement.- Parameters:
marker- themarkerargument (notnull)replacement- thereplacementargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
replaceAllBetween
public void replaceAllBetween(String beginMark, String endMark, String replacement, boolean replaceMarks)Replaces the first occurrence of ALL the content found betweenbeginMarkandendMarkwithreplacement. ThebeginMarkandendMarkare included in what is replaced ifreplaceMarksistrue.- Parameters:
beginMark- thebeginMarkargument (notnull)endMark- theendMarkargument (notnull)replacement- thereplacementargument (notnull)replaceMarks- thereplaceMarksargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
replaceBetween
Replaces all occurrences ofvaluewithreplacement, but only wherevalueis found betweenbeginMarkandendMark. Returns the number of replacements made.- Parameters:
beginMark- thebeginMarkargument (notnull)endMark- theendMarkargument (notnull)value- thevalueargument (notnull)replacement- thereplacementargument (notnull)- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
replaceFirst
Replaces the first occurrence of a specified string in this instance with another string. Returnstrueif thevaluewas found and replaced. Otherwise returnsfalse.- Parameters:
value- thevalueargument (notnull)replacement- thereplacementargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
replaceI
Replaces all occurrences ofvaluewith the decimal integerreplacement. Returns the number of replacements.- Parameters:
value- thevalueargument (notnull)replacement- thereplacementargument- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
replaceNoCase
Replaces all occurrences ofvaluewithreplacement(case insensitive). Returns the number of replacements.- Parameters:
value- thevalueargument (notnull)replacement- thereplacementargument (notnull)- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
replaceWord
Replaces all word occurrences of a specified string in this instance with another specified string. Returns the number of replacements made.Important: This method is limited to replacing 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.)
- Parameters:
value- thevalueargument (notnull)replacement- thereplacementargument (notnull)- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
restoreMaskedStrings
Restores single and/or double-quoted strings previously masked by MaskQuotedStrings.quoteTypedetermines which types of quoted strings are masked:- Both single and double quoted.
- Only single quoted strings.
- Only double quoted strings.
- Parameters:
quoteType- thequoteTypeargumentmaskedStrings- themaskedStringsargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
secureClear
public void secureClear()Removes all characters from the current StringBuilder instance, and write zero bytes to the allocated memory before deallocating. -
setNth
public void setNth(int index, String value, String delimiterChar, boolean exceptDoubleQuoted, boolean exceptEscaped)Sets the Nth substring in string in a list delimted bydelimiterChar. 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.- Parameters:
index- theindexargumentvalue- thevalueargument (notnull)delimiterChar- thedelimiterCharargument (notnull)exceptDoubleQuoted- theexceptDoubleQuotedargumentexceptEscaped- theexceptEscapedargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setString
Sets this instance to a copy of the specified string.- Parameters:
value- thevalueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
shorten
public void shorten(int numChars)Shortens the string by removing the lastnumCharschars.- Parameters:
numChars- thenumCharsargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
startsWith
Returnstrueif the string starts withsubstr. Otherwise returnsfalse. The comparison is case sensitive ifcaseSensitiveistrue, and case insensitive ifcaseSensitiveisfalse.- Parameters:
substr- thesubstrargument (notnull)caseSensitive- thecaseSensitiveargument- Returns:
- the result; this method never throws
ChilkatException
-
toCRLF
public void toCRLF()Converts line endings to CRLF (Windows) format.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
toLF
public void toLF()Converts line endings to LF-only (UNIX) format.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
toLowercase
public void toLowercase()Converts the contents to lowercase.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
toUppercase
public void toUppercase()Converts the contents to uppercase.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
trim
public void trim()Trims whitespace from both ends of the string.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
trimInsideSpaces
public void trimInsideSpaces()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.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
unobfuscate
public void unobfuscate()Unobfuscates the string.The Chilkat string obfuscation algorithm works by taking the utf-8 bytes of the string, base64 encoding it, and then scrambling the letters of the base64 encoded string. It is deterministic in that the same string will always obfuscate to the same result. It is not a secure way of encrypting a string. It is only meant to be a simple means of transforming a string into something unintelligible.
-
writeFile
Writes the contents to a file. IfemitBomistrue, 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.)- Parameters:
path- thepathargument (notnull)charset- thecharsetargument (notnull)emitBom- theemitBomargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
writeFileIfModified
Writes the contents to a file, but only if it is a new file or if the contents are different than the existing file. IfemitBomistrue, 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.)- Parameters:
path- thepathargument (notnull)charset- thecharsetargument (notnull)emitBom- theemitBomargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-