Class StringTable
- All Implemented Interfaces:
AutoCloseable
Store, load, search, sort, split, retrieve, and save ordered lists of strings.
Chilkat.StringTable is a simple ordered collection of strings.
It can append strings directly, load one string per line from files or
StringBuilder, search for substrings or wildcard matches, sort
the collection, split strings into entries, retrieve strings by index, export
the table as line-delimited text, and save the result to a file.
Ordered string collection
Store a list of strings in insertion order and retrieve individual entries by zero-based index.
Append and import
Add strings directly, append strings from a file, or load line-delimited
text from a StringBuilder.
Search strings
Find entries containing a substring or matching a wildcard pattern when filtering or locating text values.
Sort entries
Sort the string collection when deterministic ordering or user-facing display order is needed.
Split into entries
Split delimited text into separate string-table entries for easier indexing, searching, sorting, or saving.
Export and save
Convert the table back to line-delimited text, copy it to a
StringBuilder, or save the collection to a file.
Common pattern:
Use StringTable when application code needs a lightweight
ordered list of text values. Append or load the strings, search or sort as
needed, retrieve entries by index with StringAt or
StringAtSb, then export the final list as line-delimited text or
save it to a file.
For an extended overview, see StringTable 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 string to the table.voidappendFromFile(int maxLineLen, String charset, String path)Appends strings, one per line, from a file.voidAppends strings, one per line, from the contents of a StringBuilder object.voidclear()Removes all the strings from the table.intfindMatch(StringBuilder sb, boolean caseSensitive)This string table object holds strings with wildcards.intfindSubstring(int startIndex, String substr, boolean caseSensitive)Return the index of the first string in the table containingsubstr.intgetCount()The number of strings in the table.getStrings(int startIdx, int count, boolean crlf)Return the number of strings specified bycount, one per line, starting atstartIdx.intintAt(int index)Returns the Nth string in the table, converted to an integer value.voidsaveToFile(String charset, boolean bCrlf, String path)Saves the string table to a file.voidsort(boolean ascending, boolean caseSensitive)Sorts the strings in the collection in ascending or descending order.voidsplitAndAppend(String inStr, String delimiterChar, boolean exceptDoubleQuoted, boolean exceptEscaped)Splits a string into parts based on a single characterdelimiterChar.stringAt(int index)Returns the Nth string in the table.voidstringAtSb(int index, StringBuilder sb)Appends the Nth string in the table tosb.voidtoSb(StringBuilder sb)Appends the entire string table tosbusing CRLF line endings.intwordFollowing(StringBuilder sb, boolean captureEmailAddr, StringBuilder sbWord)The method performs a case-insensitive search to return the index of a table entry matchingsb, or -1 if there is no match.Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
StringTable
public StringTable()Creates a newStringTableobject.
-
-
Method Details
-
getCount
public int getCount()The number of strings in the table.- Returns:
- the value of the
Countproperty (read-only)
-
append
Appends a string to the table.- Parameters:
value- thevalueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendFromFile
Appends strings, one per line, from a file. Each line in thepathshould be no longer than the length specified inmaxLineLen. Thecharsetindicates the character encoding of the contents of the file, such asutf-8,iso-8859-1,Shift_JIS, etc.- Parameters:
maxLineLen- themaxLineLenargumentcharset- thecharsetargument (notnull)path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendFromSb
Appends strings, one per line, from the contents of a StringBuilder object.- Parameters:
sb- thesbargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
clear
public void clear()Removes all the strings from the table. -
findMatch
This string table object holds strings with wildcards. The method returns the index of the wildcarded string that matches the text insb, or -1 if no match is found.caseSensitivespecifies whether the matching should be case-sensitive.- Parameters:
sb- thesbargument (notnull)caseSensitive- thecaseSensitiveargument- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
findSubstring
Return the index of the first string in the table containingsubstr. Begins searching strings starting atstartIndex. IfcaseSensitiveistrue, then the search is case sensitive. IfcaseSensitiveisfalsethen the search is case insensitive. Returns -1 if thesubstris not found.- Parameters:
startIndex- thestartIndexargumentsubstr- thesubstrargument (notnull)caseSensitive- thecaseSensitiveargument- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
getStrings
Return the number of strings specified bycount, one per line, starting atstartIdx. To return the entire table, pass 0 values for bothstartIdxandcount. Setcrlfequal totrueto emit with CRLF line endings, orfalseto emit LF-only line endings. The last string is emitted includes the line ending.- Parameters:
startIdx- thestartIdxargumentcount- thecountargumentcrlf- thecrlfargument- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
intAt
public int intAt(int index)Returns the Nth string in the table, converted to an integer value. Theindexis 0-based. (The first string is at index 0.) Returns -1 if no string is found at the specified index. Returns 0 if the string at the specified index exist, but is not an integer.- Parameters:
index- theindexargument- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
saveToFile
Saves the string table to a file. Thecharsetis the character encoding to use, such asutf-8,iso-8859-1,windows-1252,Shift_JIS,gb2312, etc. IfbCrlfistrue, then CRLF line endings are used, otherwise LF-only line endings are used.- Parameters:
charset- thecharsetargument (notnull)bCrlf- thebCrlfargumentpath- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
sort
public void sort(boolean ascending, boolean caseSensitive)Sorts the strings in the collection in ascending or descending order. To sort in ascending order, setascendingtotrue, otherwise setascendingequal tofalse.- Parameters:
ascending- theascendingargumentcaseSensitive- thecaseSensitiveargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
splitAndAppend
public void splitAndAppend(String inStr, String delimiterChar, boolean exceptDoubleQuoted, boolean exceptEscaped)Splits a string into parts based on a single characterdelimiterChar. 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:
inStr- theinStrargument (notnull)delimiterChar- thedelimiterCharargument (notnull)exceptDoubleQuoted- theexceptDoubleQuotedargumentexceptEscaped- theexceptEscapedargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
stringAt
Returns the Nth string in the table. Theindexis 0-based. (The first string is at index 0.)- Parameters:
index- theindexargument- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
stringAtSb
Appends the Nth string in the table tosb. Theindexis 0-based. (The first string is at index 0.)- Parameters:
index- theindexargumentsb- thesbargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
toSb
Appends the entire string table tosbusing CRLF line endings.- Parameters:
sb- thesbargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
wordFollowing
The method performs a case-insensitive search to return the index of a table entry matchingsb, or -1 if there is no match. SetcaptureEmailAddrtotrueif the target word is expected to be an email address, otherwise setcaptureEmailAddrtofalse.sbWordwill receive the word (email address) following the matched text.This method helps replace the outdated Chilkat Bounce class, which was used for identifying and categorizing bounced email types.
- Parameters:
sb- thesbargument (notnull)captureEmailAddr- thecaptureEmailAddrargumentsbWord- thesbWordargument (notnull)- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-