Class Strings


  • public final class Strings
    extends Object

    This class provides convenience operations for strings.

    Author:
    BaseX Team 2005-23, BSD License, Christian Gruen
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static String capitalize​(String string)
      Capitalizes the first letter of a string.
      static String concat​(Object... objects)
      Concatenates multiple objects.
      static boolean contains​(String string, char ch)
      Checks if a string contains a character.
      static String delete​(String string, char ch)
      Deletes a character from a string.
      static String[] encodings()
      Returns a string array with all supported encodings.
      static boolean endsWith​(String string, char ch)
      Checks if a string ends with the specified character.
      static boolean eq​(String string1, String string2)
      Compares two strings for equality.
      static boolean eq​(String string, String... strings)
      Compares several strings for equality.
      static boolean eqic​(String string, String... strings)
      Compares several strings for equality, ignoring the case.
      static String md5​(String string)
      Returns an MD5 hash in lower case.
      static boolean no​(String string)
      Checks if the specified string is "no", "false", "off" or "0".
      static String normEncoding​(String encoding)
      Returns a unified representation of the specified encoding.
      static String normEncoding​(String encoding, boolean utf16)
      Returns a unified representation of the specified encoding.
      static String sha256​(String string)
      Returns an SHA256 hash in lower case.
      static String[] split​(String string, char separator)
      Splits a string around matches of the given separator.
      static String[] split​(String string, char separator, int limit)
      Splits a string around matches of the given separator.
      static boolean startsWith​(String string, char ch)
      Checks if a string starts with the specified character.
      static boolean supported​(String encoding)
      Checks if the specified encoding is supported.
      static boolean toBoolean​(String string)
      Checks if the specified string is "yes", "true", "on" or "1".
      static int toInt​(String string)
      Converts the specified string into an integer value.
      static long toLong​(String string)
      Converts the specified string into a long value.
    • Method Detail

      • toLong

        public static long toLong​(String string)
        Converts the specified string into a long value. Long.MIN_VALUE is returned if the input is invalid.
        Parameters:
        string - string to be converted
        Returns:
        resulting long value
      • toInt

        public static int toInt​(String string)
        Converts the specified string into an integer value. Integer.MIN_VALUE is returned if the input is invalid.
        Parameters:
        string - string to be converted
        Returns:
        resulting integer value
      • toBoolean

        public static boolean toBoolean​(String string)
        Checks if the specified string is "yes", "true", "on" or "1".
        Parameters:
        string - string to be checked
        Returns:
        result of check
      • eq

        public static boolean eq​(String string1,
                                 String string2)
        Compares two strings for equality. The arguments may be null.
        Parameters:
        string1 - first string
        string2 - strings to be compared
        Returns:
        true if test is successful
      • eq

        public static boolean eq​(String string,
                                 String... strings)
        Compares several strings for equality. The arguments may be null.
        Parameters:
        string - first string
        strings - strings to be compared
        Returns:
        true if one test is successful
      • eqic

        public static boolean eqic​(String string,
                                   String... strings)
        Compares several strings for equality, ignoring the case.
        Parameters:
        string - first string
        strings - strings to be compared
        Returns:
        true if test is successful
      • split

        public static String[] split​(String string,
                                     char separator)
        Splits a string around matches of the given separator.
        Parameters:
        string - string to be split
        separator - separation character
        Returns:
        resulting strings
      • split

        public static String[] split​(String string,
                                     char separator,
                                     int limit)
        Splits a string around matches of the given separator.
        Parameters:
        string - string to be split
        separator - separation character
        limit - maximum number of strings (ignored if -1)
        Returns:
        resulting strings
      • delete

        public static String delete​(String string,
                                    char ch)
        Deletes a character from a string.
        Parameters:
        string - string
        ch - character to be removed
        Returns:
        resulting token
      • contains

        public static boolean contains​(String string,
                                       char ch)
        Checks if a string contains a character.
        Parameters:
        string - string
        ch - character to search for
        Returns:
        result of check
      • md5

        public static String md5​(String string)
        Returns an MD5 hash in lower case.
        Parameters:
        string - string to be hashed
        Returns:
        md5 hash
      • sha256

        public static String sha256​(String string)
        Returns an SHA256 hash in lower case.
        Parameters:
        string - string to be hashed
        Returns:
        sha256 hash
      • normEncoding

        public static String normEncoding​(String encoding)
        Returns a unified representation of the specified encoding.
        Parameters:
        encoding - input encoding (UTF-8 is returned for a null reference)
        Returns:
        encoding
      • normEncoding

        public static String normEncoding​(String encoding,
                                          boolean utf16)
        Returns a unified representation of the specified encoding.
        Parameters:
        encoding - input encoding (UTF-8 is returned for a null reference)
        utf16 - normalize UTF-16 encoding
        Returns:
        encoding
      • supported

        public static boolean supported​(String encoding)
        Checks if the specified encoding is supported.
        Parameters:
        encoding - encoding
        Returns:
        result of check
      • capitalize

        public static String capitalize​(String string)
        Capitalizes the first letter of a string.
        Parameters:
        string - input string
        Returns:
        capitalized string
      • no

        public static boolean no​(String string)
        Checks if the specified string is "no", "false", "off" or "0".
        Parameters:
        string - string to be checked
        Returns:
        result of check
      • startsWith

        public static boolean startsWith​(String string,
                                         char ch)
        Checks if a string starts with the specified character.
        Parameters:
        string - string
        ch - character to be found
        Returns:
        result of check
      • endsWith

        public static boolean endsWith​(String string,
                                       char ch)
        Checks if a string ends with the specified character.
        Parameters:
        string - string
        ch - character to be found
        Returns:
        result of check
      • concat

        public static String concat​(Object... objects)
        Concatenates multiple objects.
        Parameters:
        objects - objects
        Returns:
        resulting string
      • encodings

        public static String[] encodings()
        Returns a string array with all supported encodings.
        Returns:
        encodings