Module org.hsqldb

Class StringUtil


  • public class StringUtil
    extends java.lang.Object
    Provides a collection of convenience methods for processing and creating objects with String value components.
    Since:
    1.7.0
    Author:
    Campbell Burnet (campbell-burnet@users dot sourceforge.net), Fred Toussi (fredt@users dot sourceforge.net)
    • Constructor Summary

      Constructors 
      Constructor Description
      StringUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String arrayToString​(java.lang.Object array)
      Builds a bracketed CSV list from the array
      static java.lang.String getList​(int[] s, java.lang.String separator, java.lang.String quote)
      Builds a CSV list from the specified int[], separator String and quote String.
      static java.lang.String getList​(long[] s, java.lang.String separator, java.lang.String quote)  
      static java.lang.String getList​(java.lang.String[][] s, java.lang.String separator, java.lang.String quote)
      Builds a CSV list from the specified String[][], separator string and quote string.
      static java.lang.String getList​(java.lang.String[] s, java.lang.String separator, java.lang.String quote)
      Builds a CSV list from the specified String[], separator string and quote string.
      static boolean isEmpty​(java.lang.String s)
      Checks if text is empty (characters <= space)
      static int rightTrimSize​(java.lang.String s)
      Returns the size of substring that does not contain any trailing spaces
      static int skipSpaces​(java.lang.String s, int start)
      Skips any spaces at or after start and returns the index of first non-space character;
      static java.lang.String[] split​(java.lang.String s, java.lang.String separator)
      Splits the string into an array, using the separator.
      static java.lang.String toLowerSubset​(java.lang.String source, char substitute)
      Returns a string with non-alphanumeric chars converted to the substitute character.
      static java.lang.String toPaddedString​(java.lang.String source, int length, char pad, boolean trailing)  
      static java.lang.String toPaddedString​(java.lang.String source, int length, java.lang.String pad, boolean trailing)  
      static java.lang.String toZeroPaddedString​(long value, int precision, int maxSize)
      If necessary, adds zeros to the beginning of a value so that the total length matches the given precision, otherwise trims the right digits.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StringUtil

        public StringUtil()
    • Method Detail

      • toZeroPaddedString

        public static java.lang.String toZeroPaddedString​(long value,
                                                          int precision,
                                                          int maxSize)
        If necessary, adds zeros to the beginning of a value so that the total length matches the given precision, otherwise trims the right digits. Then if maxSize is smaller than precision, trims the right digits to maxSize. Negative values are treated as positive
        Parameters:
        value - long
        precision - int
        maxSize - int
        Returns:
        String
      • toPaddedString

        public static java.lang.String toPaddedString​(java.lang.String source,
                                                      int length,
                                                      char pad,
                                                      boolean trailing)
      • toPaddedString

        public static java.lang.String toPaddedString​(java.lang.String source,
                                                      int length,
                                                      java.lang.String pad,
                                                      boolean trailing)
      • toLowerSubset

        public static java.lang.String toLowerSubset​(java.lang.String source,
                                                     char substitute)
        Returns a string with non-alphanumeric chars converted to the substitute character. A digit first character is also converted. By sqlbob@users
        Parameters:
        source - string to convert
        substitute - character to use
        Returns:
        converted string
      • arrayToString

        public static java.lang.String arrayToString​(java.lang.Object array)
        Builds a bracketed CSV list from the array
        Parameters:
        array - an array of Objects
        Returns:
        string
      • getList

        public static java.lang.String getList​(java.lang.String[] s,
                                               java.lang.String separator,
                                               java.lang.String quote)
        Builds a CSV list from the specified String[], separator string and quote string.
        • All arguments are assumed to be non-null.
        • Separates each list element with the value of the separator argument.
        • Prepends and appends each element with the value of the quote argument.
        • No attempt is made to escape the quote character sequence if it is found internal to a list element.
        Parameters:
        separator - the String to use as the list element separator
        quote - the String with which to quote the list elements
        s - array of String objects
        Returns:
        a CSV list
      • getList

        public static java.lang.String getList​(int[] s,
                                               java.lang.String separator,
                                               java.lang.String quote)
        Builds a CSV list from the specified int[], separator String and quote String.
        • All arguments are assumed to be non-null.
        • Separates each list element with the value of the separator argument.
        • Prepends and appends each element with the value of the quote argument.
        Parameters:
        s - the array of int values
        separator - the String to use as the separator
        quote - the String with which to quote the list elements
        Returns:
        a CSV list
      • getList

        public static java.lang.String getList​(long[] s,
                                               java.lang.String separator,
                                               java.lang.String quote)
      • getList

        public static java.lang.String getList​(java.lang.String[][] s,
                                               java.lang.String separator,
                                               java.lang.String quote)
        Builds a CSV list from the specified String[][], separator string and quote string.
        • All arguments are assumed to be non-null.
        • Uses only the first element in each subarray.
        • Separates each list element with the value of the separator argument.
        • Prepends and appends each element with the value of the quote argument.
        • No attempt is made to escape the quote character sequence if it is found internal to a list element.
        Parameters:
        separator - the String to use as the list element separator
        quote - the String with which to quote the list elements
        s - the array of String array objects
        Returns:
        a CSV list
      • isEmpty

        public static boolean isEmpty​(java.lang.String s)
        Checks if text is empty (characters <= space)
        Parameters:
        s - java.lang.String
        Returns:
        boolean true if text is null or empty, false otherwise
      • rightTrimSize

        public static int rightTrimSize​(java.lang.String s)
        Returns the size of substring that does not contain any trailing spaces
        Parameters:
        s - the string
        Returns:
        trimmed size
      • skipSpaces

        public static int skipSpaces​(java.lang.String s,
                                     int start)
        Skips any spaces at or after start and returns the index of first non-space character;
        Parameters:
        s - the string
        start - index to start
        Returns:
        index of first non-space
      • split

        public static java.lang.String[] split​(java.lang.String s,
                                               java.lang.String separator)
        Splits the string into an array, using the separator. If separator is not found in the string, the whole string is returned in the array.
        Parameters:
        s - the string
        separator - the separator
        Returns:
        array of strings