de.esprit.common.util

## Class TextUtil

- java.lang.Object
- - de.esprit.common.util.TextUtil

-     public class TextUtil
      extends java.lang.Object

  This class collects text utility methods
  Author:
    Rainer Buesch

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `capitalizeFirstCharOf(java.lang.String str)`
    `static java.lang.String` | `cleanString(java.lang.String str)` Cleans the String from unprintable characters.
    `static int` | `countNewLines(java.lang.String str)` Counts the number of CRs in the string.
    `static int` | `countOccurrences(char c, java.lang.String str)` Counts the occurrences of the given char in the string.
    `static int` | `countWords(java.lang.String str)` Counts the number of words in the string.
    `static java.lang.String` | `fill(int length)`
    `static java.lang.String` | `fill(int length, boolean leading, java.lang.String str)`
    `static java.lang.String` | `fill(int length, char fillchar)`
    `static java.lang.String` | `fill(int length, char fillchar, boolean leading, java.lang.String str)`
    `static java.lang.String` | `fill(int length, char fillchar, java.lang.String str)`
    `static java.lang.String` | `fill(int length, java.lang.String str)`
    `static java.lang.String` | `firstWordOf(java.lang.String str)` Returns the first word of the given string using the default word separator characters (BLANK, TAB).
    `static java.lang.String` | `firstWordOf(java.lang.String str, java.lang.String separatorChars)` Returns the first word of the given string using the given word separator characters.
    `static char` | `getRandomChar()`
    `static java.lang.String` | `getRandomString(int length)`
    `static java.lang.String` | `getWord(int index, java.lang.String str, java.lang.String delim)`
    `static boolean` | `isQuoted(java.lang.String str)` Checks whether the given String is enclosed in single quotes
    `static java.lang.String` | `multiplyWord(java.lang.String word, int times, int addLFs)` Builds a String by repeating the given word n times.
    `static java.lang.String` | `quote(java.lang.Object o)`
    `static java.lang.String` | `quoteCR(java.lang.String str)` Converts any '\n' character to a "\n" char sequence
    `static boolean` | `regionMatches(java.lang.String str, java.lang.String match)`
    `static java.lang.String` | `replace(java.lang.String source, java.lang.String oldVal, java.lang.String newVal)` Replaces all occurrences of oldVal by newVal.
    `static java.lang.String` | `stuff(java.lang.String str)` Multiple white spaces are replaced by a single blank, leading and trailing white spaces are removed, RETURN and TAB characters are replaced by a blank.
    `static java.lang.String` | `tag(java.lang.String str)` Quotes the given string to an HTML Tag
    `static java.lang.String` | `toHtml(java.lang.String str)` Converts special characters in the string to an HTML compatible format
    `static java.lang.String[]` | `toMultiLineArray(java.lang.String str)` Returns the given String splitted up into lines.
    `static java.util.List<java.lang.String>` | `toMultiLineList(java.lang.String str)` Returns the given String splitted up into lines.
    `static java.lang.String` | `toXml(java.lang.String s)` quotes < and > chars.
    `static java.lang.String` | `toXMLAttributeList(java.util.Map map)` Print out the key-value pairs of the map in a format of an XML attribute list.
    `static java.lang.String` | `trim(java.lang.String str)` Strips leading and trailing characters away from the string.
    `static java.lang.String` | `trimLeading(java.lang.String str)`
    `static java.lang.String` | `trimLower(java.lang.String str)` Null-safe conversion to lower case
    `static java.lang.String` | `trimNotNull(java.lang.String str)` Strips leading and trailing characters away from the string.
    `static java.lang.String` | `trimTrailing(java.lang.String str)`
    `static java.lang.String` | `trimUpper(java.lang.String str)` Null-safe conversion to upper case
    `static java.lang.String` | `truncate(int length, java.lang.String str)` Truncates the string to the given length.
    `static java.lang.String` | `unquote(java.lang.String str)` Removes single quotes from a string if it is single quoted.
    `static java.lang.String` | `unquoteCR(java.lang.String str)` Converts a "\n" char sequence to a real '\n' character.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### trimNotNull

          public static java.lang.String trimNotNull(java.lang.String str)

      Strips leading and trailing characters away from the string. The resulting string is never null.

    - #### trim

          public static java.lang.String trim(java.lang.String str)

      Strips leading and trailing characters away from the string. The argument may be null.

    - #### trimTrailing

          public static java.lang.String trimTrailing(java.lang.String str)

    - #### trimLeading

          public static java.lang.String trimLeading(java.lang.String str)

    - #### truncate

          public static java.lang.String truncate(int length,
                                  java.lang.String str)

      Truncates the string to the given length. Appends '...' if the string was actually truncated.

    - #### trimUpper

          public static java.lang.String trimUpper(java.lang.String str)

      Null-safe conversion to upper case

    - #### trimLower

          public static java.lang.String trimLower(java.lang.String str)

      Null-safe conversion to lower case

    - #### getWord

          public static java.lang.String getWord(int index,
                                 java.lang.String str,
                                 java.lang.String delim)

    - #### multiplyWord

          public static java.lang.String multiplyWord(java.lang.String word,
                                      int times,
                                      int addLFs)

      Builds a String by repeating the given word n times. After 'addLFs' words a line feed character is inserted.

    - #### countWords

          public static int countWords(java.lang.String str)

      Counts the number of words in the string.

    - #### countNewLines

          public static int countNewLines(java.lang.String str)

      Counts the number of CRs in the string.

    - #### countOccurrences

          public static int countOccurrences(char c,
                             java.lang.String str)

      Counts the occurrences of the given char in the string.

    - #### replace

          public static java.lang.String replace(java.lang.String source,
                                 java.lang.String oldVal,
                                 java.lang.String newVal)

      Replaces all occurrences of oldVal by newVal.

    - #### stuff

          public static java.lang.String stuff(java.lang.String str)

      Multiple white spaces are replaced by a single blank, leading and trailing white spaces are removed, RETURN and TAB characters are replaced by a blank.

    - #### cleanString

          public static java.lang.String cleanString(java.lang.String str)

      Cleans the String from unprintable characters. All unprintable characters will be converted to '.' characters.

    - #### toHtml

          public static java.lang.String toHtml(java.lang.String str)

      Converts special characters in the string to an HTML compatible format

    - #### toXml

          public static java.lang.String toXml(java.lang.String s)

      quotes < and > chars.

    - #### getRandomString

          public static java.lang.String getRandomString(int length)

    - #### getRandomChar

          public static char getRandomChar()

    - #### regionMatches

          public static boolean regionMatches(java.lang.String str,
                              java.lang.String match)

    - #### quoteCR

          public static java.lang.String quoteCR(java.lang.String str)

      Converts any '\n' character to a "\n" char sequence

    - #### tag

          public static java.lang.String tag(java.lang.String str)

      Quotes the given string to an HTML Tag

    - #### unquoteCR

          public static java.lang.String unquoteCR(java.lang.String str)

      Converts a "\n" char sequence to a real '\n' character.

    - #### firstWordOf

          public static java.lang.String firstWordOf(java.lang.String str)

      Returns the first word of the given string using the default word separator characters (BLANK, TAB).

    - #### firstWordOf

          public static java.lang.String firstWordOf(java.lang.String str,
                                     java.lang.String separatorChars)

      Returns the first word of the given string using the given word separator characters.

    - #### quote

          public static java.lang.String quote(java.lang.Object o)

    - #### unquote

          public static java.lang.String unquote(java.lang.String str)

      Removes single quotes from a string if it is single quoted. Otherwise the string remains unchanged.

    - #### isQuoted

          public static boolean isQuoted(java.lang.String str)

      Checks whether the given String is enclosed in single quotes

    - #### fill

          public static java.lang.String fill(int length)

    - #### fill

          public static java.lang.String fill(int length,
                              char fillchar)

    - #### fill

          public static java.lang.String fill(int length,
                              java.lang.String str)

    - #### fill

          public static java.lang.String fill(int length,
                              boolean leading,
                              java.lang.String str)

    - #### fill

          public static java.lang.String fill(int length,
                              char fillchar,
                              java.lang.String str)

    - #### fill

          public static java.lang.String fill(int length,
                              char fillchar,
                              boolean leading,
                              java.lang.String str)

    - #### capitalizeFirstCharOf

          public static java.lang.String capitalizeFirstCharOf(java.lang.String str)

    - #### toXMLAttributeList

          public static java.lang.String toXMLAttributeList(java.util.Map map)

      Print out the key-value pairs of the map in a format of an XML attribute list. This output can directly be used for creating XML tags.

    - #### toMultiLineArray

          public static java.lang.String[] toMultiLineArray(java.lang.String str)

      Returns the given String splitted up into lines.
      See Also:
        `toMultiLineList(String)`

    - #### toMultiLineList

          public static java.util.List<java.lang.String> toMultiLineList(java.lang.String str)

      Returns the given String splitted up into lines. The resulting strings will be trimmed and won't contain any '\r' or '\n' characters.

Copyright © 2014 EsprIT-Systems. All Rights Reserved.