Class StringUtil


  • public class StringUtil
    extends Object
    Some utility methods specialized in string manipulation
    Since:
    4.5
    Author:
    Marco Meschieri - LogicalDOC
    • Constructor Detail

      • StringUtil

        public StringUtil()
    • Method Detail

      • split

        public static String split​(String src,
                                   char separator,
                                   int tokenSize)
        Splits a string into tokens separated by a separator
        Parameters:
        src - The source string
        separator - The separator character
        tokenSize - Size or each token
        Returns:
        the string with separators
      • split

        public static String[] split​(String src,
                                     int tokenSize)
        Splits a string into an array of tokens
        Parameters:
        src - The source string
        tokenSize - size of each token
        Returns:
        array of splitted tokens
      • writeToString

        public static String writeToString​(Reader reader)
                                    throws IOException
        Writes to UFT-8 encoding.
        Parameters:
        reader - the reader over a string
        Returns:
        a string with the contents readed from the reader
        Throws:
        IOException - raised in case the reader failed to read or if the string cannot be written
      • writeToString

        public static String writeToString​(Reader reader,
                                           String targetEncoding)
                                    throws IOException
        Writes the content from the reader in a string encoded as specified.
        Parameters:
        reader - Attention, this will be closed at the end of invocation
        targetEncoding - The output string encoding
        Returns:
        The encoded string
        Throws:
        IOException - raised in case the reader is unable to get the contents
      • collectionToString

        public static String collectionToString​(Collection<?> collection,
                                                String separator)
      • matches

        public static boolean matches​(String str,
                                      String[] includes,
                                      String[] excludes)
        Check if a given string matches the includes and not the excludes
        Parameters:
        str - The string to consider
        includes - list of includes regular expressions
        excludes - list of excludes regular expressions
        Returns:
        true only if the passed string matches the includes and not the excludes
      • unaccent

        public static String unaccent​(String src)
        Converts the non latin chars in the nearest ASCII char
        Parameters:
        src - the source string to process
        Returns:
        the unaccented string