Class StringUtils


  • public class StringUtils
    extends Object
    • Method Detail

      • replace

        public static String replace​(String text,
                                     String targetText,
                                     String newText)
        Replace all occurances of the target text with the provided replacement text. Both target and replacement may be regular expressions - see java.util.regex.Matcher.
        Parameters:
        text - Text to modify
        targetText - Text to find and replace
        newText - New text
        Returns:
        Updated text
      • isNull

        public static boolean isNull​(String string)
        Null (or zero-length) String?
      • truncateAtWhitespace

        public static String truncateAtWhitespace​(String text,
                                                  int length)
        Truncate text on a whitespace boundary (near a specified length). The length of the resultant string will be in the range:
        (requested-length * .25) ~ (requested-length * 1.5)
        Parameters:
        text - Text to truncate
        length - Target length
        Returns:
        Truncated text
      • trimFront

        public static String trimFront​(String text,
                                       char character)
        Trim specified charcater from front of string
        Parameters:
        text - Text
        character - Character to remove
        Returns:
        Trimmed text
      • trimEnd

        public static String trimEnd​(String text,
                                     char character)
        Trim specified charcater from end of string
        Parameters:
        text - Text
        character - Character to remove
        Returns:
        Trimmed text
      • trimAll

        public static String trimAll​(String text,
                                     char character)
        Trim specified charcater from both ends of a String
        Parameters:
        text - Text
        character - Character to remove
        Returns:
        Trimmed text
      • capitalize

        public static String capitalize​(String text)
        Capitlize each word in a string (journal titles, etc)
        Parameters:
        text - Text to inspect
        Returns:
        Capitalized text
      • removeCharacterOrRangeAsWord

        public static String removeCharacterOrRangeAsWord​(String source,
                                                          String pattern)
        Remove a character (or range of characters) from a string. If the character is in a word, remove the entire word.
        Parameters:
        source - String to edit
        pattern - Character (or range) to remove. Range is a regular expression: [,-/] or [,-/]
        Returns:
        Modified text
      • removeCharacterOrRangeAsCharacter

        public static String removeCharacterOrRangeAsCharacter​(String source,
                                                               String pattern)
        Remove a character (or range of characters) from a string. If the character is at the start or end of a word, remove the character only (leave the word in place).
        Parameters:
        source - String to edit
        pattern - Character (or range) to remove. Range is a regular expression: [,-/] or [,-/]
        Returns:
        Modified text