Class StringUtils


  • public class StringUtils
    extends Object
    Some simple string utilities
    Author:
    markr
    • Constructor Detail

      • StringUtils

        public StringUtils()
    • Method Detail

      • removeBOM

        public static String removeBOM​(String value)
        A String might have some byte order mark preceding the string (for example InputStreamReader might include this). These are not visible in the string but do change the underlying bytes compared to a string without this BOM and comparing them will fail despite looking identical. This method will remove the BOM from a copy of this string which is returned.
        Parameters:
        value - to remove BOM from
        Returns:
        BOM-less copy
      • splitByAnythingExceptAlphaNumeric

        public static String[] splitByAnythingExceptAlphaNumeric​(String toSplit)
        split string by anything but alpha numeric characters, i.e., a-zA-Z0-9
        Parameters:
        toSplit - string to split
        Returns:
        split string
      • isNullOrBlank

        public static boolean isNullOrBlank​(String string)
        Verify if null or blank
        Parameters:
        string - to verify
        Returns:
        true when null or blank
      • removeInitialStringWhenPresent

        public static String removeInitialStringWhenPresent​(String theString,
                                                            String initialString)
        Remove the given string from the beginning of the string if present and return result
        Parameters:
        theString - to alter
        initialString - to remove if present
        Returns:
        altered string
      • removeEndingStringWhenPresent

        public static String removeEndingStringWhenPresent​(String theString,
                                                           String endString)
        Remove the given string from the end of the string if present and return result
        Parameters:
        theString - to alter
        endString - to remove if present
        Returns:
        altered string
      • zeroPaddedStringOf

        public static String zeroPaddedStringOf​(int value,
                                                int numPadding)
        Value to be converted to string with given zero padding in from
        Parameters:
        value - to convert
        numPadding - to apply
        Returns:
        created string
      • printBytes

        public static String printBytes​(String str,
                                        Charset encoding)
        print bytes of the String
        Parameters:
        str - to print bytes for
        encoding - to apply
        Returns:
        String with printed bytes
      • printChars

        public static String printChars​(String str)
        print chars of the String
        Parameters:
        str - to print chars for
        Returns:
        String with printed bytes