Class StringTools

java.lang.Object
de.intarsys.tools.string.StringTools

public class StringTools extends Object
A tool class for the handling of strings.
  • Field Details

  • Constructor Details

    • StringTools

      public StringTools()
  • Method Details

    • breakForced

      public static String breakForced(String value, int max, String breakPattern)
    • capitalize

      public static String capitalize(String text)
      Capitalizes the first letter of the text.
      Parameters:
      text -
      Returns:
      a capitalized version of the text
    • clear

      public static void clear(char[] value)
      clear character array content.
      Parameters:
      value - The value to be cleared
    • format

      public static String format(Object value, String format)
      Create a string representation and format value according to the instructions in format.

      If value is null, the empty string is returned.

    • formatDate

      protected static String formatDate(Object value, String format)
    • formatDateDefault

      protected static String formatDateDefault(Date date)
      Parameters:
      value -
    • formatFloat

      protected static String formatFloat(Object value, String format)
    • formatInteger

      protected static String formatInteger(Object value, String format)
    • formatPath

      protected static String formatPath(Object value, String string)
    • formatString

      protected static String formatString(Object value, String format)
    • getCommonPrefix

      public static String getCommonPrefix(String a, String b, boolean ignoreCase)
    • getFirstLine

      public static String getFirstLine(String text)
      The first line of text (all characters up to the first occurence of either "\n" or "\r".
      Parameters:
      text - The text where the first line is looked up.
      Returns:
      The first line of text
    • getLeading

      public static String getLeading(String value, int count)
    • getLineCount

      public static int getLineCount(String text)
      The number of lines in text. This is 1 + the number of "\n" in text.
      Parameters:
      text - The text where the lines are counted.
      Returns:
      The number of lines in text. This is 1 + the number of "\n" in text.
    • getTrailing

      public static String getTrailing(String value, int count)
    • isEmpty

      public static boolean isEmpty(char[] value)
      true if value is "empty" in any respect.

      This is the case when value == null, value has no characters or only whitespace.

      Parameters:
      value - The value to be inspected for emptyness.
      Returns:
      true if value is "empty" in any respect.
    • isEmpty

      public static boolean isEmpty(String value)
      true if value is "empty" in any respect.

      This is the case when value == null, value has no characters or only whitespace.

      Parameters:
      value - The value to be inspected for emptyness.
      Returns:
      true if value is "empty" in any respect.
    • isNumeric

      public static boolean isNumeric(String value)
      true if value seems to be a numeric value. To qualify only the first character is examined. value qualifies as numeric if the first character is a digit, a "+", a "-" or a ".".
      Parameters:
      value -
      Returns:
      true if value seems to be numeric.
    • join

      public static String join(List<String> elements, String separator)
      Joins a List of Strings to a single one. All elements are separated by the separator.
      Parameters:
      elements - List of Strings
      separator - a String used as a separator between two elements, e.g. "\n" for a new line. May be null.
      Returns:
      the joined string
    • join

      public static String join(String[] elements, String separator)
      Joins an array of Strings to a single one. All elements are separated by the separator.
      Parameters:
      elements - array of Strings
      separator - a String used as a separator between two elements, e.g. "\n" for a new line. May be null.
      Returns:
      the joined string
    • padLeft

      public static String padLeft(String value, int count)
    • padRight

      public static String padRight(String value, int count)
    • parseArgs

      protected static String[] parseArgs(String string)
    • parseArgsString

      protected static String parseArgsString(String string)
    • parseCommandline

      public static String[] parseCommandline(String line)
      Parse a commandline string with the default escape character.
      Parameters:
      line - The commandline string.
      Returns:
      The array of string tokens in the commandline string.
    • parseCommandline

      public static String[] parseCommandline(String line, char escape)
      Parse a commandline string.
      Parameters:
      line - The commandline string.
      Returns:
      The array of string tokens in the commandline string.
    • safeString

      public static String safeString(Object object)
      Create a string representation of object that is guaranteed not to fail in any case.
      Parameters:
      object - The object to be printed.
      Returns:
      Create a string representation of object that is guaranteed not to fail in any case.
    • toByteArray

      public static byte[] toByteArray(String value)
      Create a byte array from the string. This is simply a fast version of getBytes, ignoring any encoding.

      If you use this, you should be sure you will encounter valid ascii characters only!

      Parameters:
      value -
      Returns:
      A byte array created from value, ignoring high byte.
    • toString

      public static String toString(byte[] value)
      Create a string from the byte array. This is simply a fast version of new String(), ignoring any encoding.

      If you use this, you should be sure you will encounter valid ascii characters only!

      Parameters:
      value -
      Returns:
      A string created from the byte values in value.
    • trimAlphaNumeric

      public static String trimAlphaNumeric(String value)
      Create a string containing only the alphanumeric content of value.
      Parameters:
      value - The string to be trimmed.
      Returns:
      A string containing only the alphanumeric content of value.
    • trimLeft

      public static String trimLeft(String value)
      Create a new string from value without leading whitespace.
      Parameters:
      value - The string to be stripped.
      Returns:
      A copy of value with leading whitespace stripped.
    • trimRight

      public static String trimRight(String value)
      Create a new string from value without trailing whitespace.
      Parameters:
      value - The string to be stripped.
      Returns:
      A copy of value with trailing whitespace stripped.