Class StringTable

java.lang.Object
com.chilkatsoft.chilkat2.ChilkatObject
com.chilkatsoft.chilkat2.StringTable
All Implemented Interfaces:
AutoCloseable

public class StringTable extends ChilkatObject
<section class="stringtable-summary">

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 Details

    • StringTable

      public StringTable()
      Creates a new StringTable object.
  • Method Details

    • getCount

      public int getCount()
      The number of strings in the table.
      Returns:
      the value of the Count property (read-only)
    • append

      public void append​(String value)
      Appends a string to the table.
      Parameters:
      value - the value argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • appendFromFile

      public void appendFromFile​(int maxLineLen, String charset, String path)
      Appends strings, one per line, from a file. Each line in the path should be no longer than the length specified in maxLineLen. The charset indicates the character encoding of the contents of the file, such as utf-8, iso-8859-1, Shift_JIS, etc.
      Parameters:
      maxLineLen - the maxLineLen argument
      charset - the charset argument (not null)
      path - the path argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • appendFromSb

      public void appendFromSb​(StringBuilder sb)
      Appends strings, one per line, from the contents of a StringBuilder object.
      Parameters:
      sb - the sb argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • clear

      public void clear()
      Removes all the strings from the table.
    • findMatch

      public int findMatch​(StringBuilder sb, boolean caseSensitive)
      This string table object holds strings with wildcards. The method returns the index of the wildcarded string that matches the text in sb, or -1 if no match is found. caseSensitive specifies whether the matching should be case-sensitive.
      Parameters:
      sb - the sb argument (not null)
      caseSensitive - the caseSensitive argument
      Returns:
      the result (see ChilkatObject.getLastMethodSuccess() where the description mentions failure)
    • findSubstring

      public int findSubstring​(int startIndex, String substr, boolean caseSensitive)
      Return the index of the first string in the table containing substr. Begins searching strings starting at startIndex. If caseSensitive is true, then the search is case sensitive. If caseSensitive is false then the search is case insensitive. Returns -1 if the substr is not found.
      Parameters:
      startIndex - the startIndex argument
      substr - the substr argument (not null)
      caseSensitive - the caseSensitive argument
      Returns:
      the result (see ChilkatObject.getLastMethodSuccess() where the description mentions failure)
    • getStrings

      public String getStrings​(int startIdx, int count, boolean crlf)
      Return the number of strings specified by count, one per line, starting at startIdx. To return the entire table, pass 0 values for both startIdx and count. Set crlf equal to true to emit with CRLF line endings, or false to emit LF-only line endings. The last string is emitted includes the line ending.
      Parameters:
      startIdx - the startIdx argument
      count - the count argument
      crlf - the crlf argument
      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. The index is 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 - the index argument
      Returns:
      the result (see ChilkatObject.getLastMethodSuccess() where the description mentions failure)
    • saveToFile

      public void saveToFile​(String charset, boolean bCrlf, String path)
      Saves the string table to a file. The charset is the character encoding to use, such as utf-8, iso-8859-1, windows-1252, Shift_JIS, gb2312, etc. If bCrlf is true, then CRLF line endings are used, otherwise LF-only line endings are used.
      Parameters:
      charset - the charset argument (not null)
      bCrlf - the bCrlf argument
      path - the path argument (not null)
      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, set ascending to true, otherwise set ascending equal to false.
      Parameters:
      ascending - the ascending argument
      caseSensitive - the caseSensitive argument
      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 character delimiterChar. 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.
      Parameters:
      inStr - the inStr argument (not null)
      delimiterChar - the delimiterChar argument (not null)
      exceptDoubleQuoted - the exceptDoubleQuoted argument
      exceptEscaped - the exceptEscaped argument
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • stringAt

      public String stringAt​(int index)
      Returns the Nth string in the table. The index is 0-based. (The first string is at index 0.)
      Parameters:
      index - the index argument
      Returns:
      the result (never null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • stringAtSb

      public void stringAtSb​(int index, StringBuilder sb)
      Appends the Nth string in the table to sb. The index is 0-based. (The first string is at index 0.)
      Parameters:
      index - the index argument
      sb - the sb argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • toSb

      public void toSb​(StringBuilder sb)
      Appends the entire string table to sb using CRLF line endings.
      Parameters:
      sb - the sb argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • wordFollowing

      public int wordFollowing​(StringBuilder sb, boolean captureEmailAddr, StringBuilder sbWord)
      The method performs a case-insensitive search to return the index of a table entry matching sb, or -1 if there is no match. Set captureEmailAddr to true if the target word is expected to be an email address, otherwise set captureEmailAddr to false. sbWord will 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 - the sb argument (not null)
      captureEmailAddr - the captureEmailAddr argument
      sbWord - the sbWord argument (not null)
      Returns:
      the result (see ChilkatObject.getLastMethodSuccess() where the description mentions failure)