Class StringUtils

java.lang.Object
com.reportmill.base.StringUtils

public class StringUtils extends Object
This class is a collection of convenient static String utils.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    add(String s1, String s2)
    Adds the two strings together (treats nulls as empty strings).
    static String
    add(String s1, String s2, String aSeparator)
    Adds the two strings together with separator (treats nulls as empty strings, ommitting sep if either is null).
    static String
    delete(String aString, String aSearch)
    Returns the result of deleting from the given string any occurance of the search string.
    static String
    deleteIC(String aString, String aSearch)
    Returns the result of deleting from the given string any occurance of the search string (ignores case).
    static String
    Returns the given path string minus the last part.
    static String
    Returns the given path string minus its extension.
    static double
    Returns an double value by parsing the given string.
    static double
    doubleValue(String aString, int aStart)
    Returns an double value by parsing the given string starting at the given index.
    static boolean
    Returns whether s1 ends with s2, ignoring case.
    static boolean
    Returns whether s1 equals s2, ignoring case.
    static String
    Returns the given string with the first char demoted to lowercase.
    static String
    Returns the given string with the first char promoted to uppercase.
    static float
    floatValue(String aString)
    Returns an float value by parsing the given string.
    static byte[]
    getBytes(String aString)
    Returns the ASCII bytes of the given string (ISO-Latin).
    static byte[]
    getBytes(String aString, String enc)
    Returns the bytes of the given string in the requested char encoding.
    static String
    getISOLatinString(byte[] bytes)
    Returns a string from the given ASCII bytes.
    static String
    getISOLatinString(byte[] bytes, int offset, int length)
    Returns a string from the given ASCII bytes (from offset to offset+length).
    static int
    Returns the index of search string s2 in given string s1, ignores case.
    static int
    indexOfIC(String s1, String s2, int start)
    Returns the index of search string s2 in given string s1, ignores case and starts at start char index.
    static int
    intValue(String aString)
    Returns an int value by parsing the given string.
    static String
    join(Object[] parts, String separator)
    Allows you to take an array of strings and concatenate them together with a separator
    static String
    join(Object[] parts, String separator, int numElements)
    Allows you to take an array of strings and concatenate them together with a separator
    static String
    Returns the last part of a path string.
    static String
    Returns the file name of the given path string (minus parent directory and extension).
    static int
    length(String aString)
    Returns the length of given string (supports null).
    static String
    String promotion - returns either the given string or empty string (if given string is null).
    static String
    String demotion - returns either the given string or null (if given string length is zero).
    static RMRange
    nextKeyRangeAfterIndex(String aString, int anIndex, RMRange aRange)
    Returns the range of the next occurance of @delimited@ text.
    static String
    or(String s1, String s2)
    Returns the first non-null string of the two given strings (or null).
    static String
    Returns the extension of the given string (or null if no extension).
    static String
    Returns the extension of the given string (or the string if no extension).
    static String
    replace(String s, int start, int end, String withString)
    Returns the result of replacing in the given string the char range with the with-string.
    static String
    replace(String aString, String search, char replace)
    Returns the result of replacing in the given string any occurance of the search string with the replace-char.
    static String
    replace(String aString, String search, String replace)
    Returns the result of replacing in the given string any occurance of the search string with the replace-string.
    static String
    replaceIC(String aString, String search, String replace)
    Returns the result of replacing in given string any occurance of search string with replace-string (ignore case).
    static List
    separate(String aString, String aSeparator)
    Returns a list of parts of given string separated by the given delimiter.
    static List
    separate(String aString, String aSeparator, boolean stripLeadingSpaces)
    Returns a list of parts of given string separated by the given delimiter, with option to strip leading space.
    static boolean
    Returns whether s1 starts with s2, ignoring case.
    static String
    toString(float aValue)
    Returns a string representation of the given float to (at most) 3 significant digits.
    static String
    toString(float aValue, int significantDigits)
    Returns a string representation of the given float to the given number of significant digits.
    static String
    wrap(String aString, int approximateWidth)
    Returns string wrapped to approximate width (quick and dirty line wrapping for use in things like option panes).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • length

      public static int length(String aString)
      Returns the length of given string (supports null).
    • add

      public static String add(String s1, String s2)
      Adds the two strings together (treats nulls as empty strings).
    • add

      public static String add(String s1, String s2, String aSeparator)
      Adds the two strings together with separator (treats nulls as empty strings, ommitting sep if either is null).
    • min

      public static String min(String s)
      String demotion - returns either the given string or null (if given string length is zero).
    • max

      public static String max(String s)
      String promotion - returns either the given string or empty string (if given string is null).
    • or

      public static String or(String s1, String s2)
      Returns the first non-null string of the two given strings (or null).
    • toString

      public static String toString(float aValue)
      Returns a string representation of the given float to (at most) 3 significant digits.
    • toString

      public static String toString(float aValue, int significantDigits)
      Returns a string representation of the given float to the given number of significant digits.
    • nextKeyRangeAfterIndex

      public static RMRange nextKeyRangeAfterIndex(String aString, int anIndex, RMRange aRange)
      Returns the range of the next occurance of @delimited@ text.
    • pathExtension

      public static String pathExtension(String aString)
      Returns the extension of the given string (or null if no extension).
    • pathExtension2

      public static String pathExtension2(String aString)
      Returns the extension of the given string (or the string if no extension).
    • deletePathExtension

      public static String deletePathExtension(String aString)
      Returns the given path string minus its extension.
    • lastPathComponent

      public static String lastPathComponent(String aString)
      Returns the last part of a path string.
    • deleteLastPathComponent

      public static String deleteLastPathComponent(String aString)
      Returns the given path string minus the last part.
    • lastPathComponentNoExt

      public static String lastPathComponentNoExt(String aString)
      Returns the file name of the given path string (minus parent directory and extension).
    • delete

      public static String delete(String aString, String aSearch)
      Returns the result of deleting from the given string any occurance of the search string.
    • deleteIC

      public static String deleteIC(String aString, String aSearch)
      Returns the result of deleting from the given string any occurance of the search string (ignores case).
    • replace

      public static String replace(String s, int start, int end, String withString)
      Returns the result of replacing in the given string the char range with the with-string.
    • replace

      public static String replace(String aString, String search, char replace)
      Returns the result of replacing in the given string any occurance of the search string with the replace-char.
    • replace

      public static String replace(String aString, String search, String replace)
      Returns the result of replacing in the given string any occurance of the search string with the replace-string.
    • replaceIC

      public static String replaceIC(String aString, String search, String replace)
      Returns the result of replacing in given string any occurance of search string with replace-string (ignore case).
    • separate

      public static List separate(String aString, String aSeparator)
      Returns a list of parts of given string separated by the given delimiter.
    • separate

      public static List separate(String aString, String aSeparator, boolean stripLeadingSpaces)
      Returns a list of parts of given string separated by the given delimiter, with option to strip leading space.
    • intValue

      public static int intValue(String aString)
      Returns an int value by parsing the given string.
    • floatValue

      public static float floatValue(String aString)
      Returns an float value by parsing the given string.
    • doubleValue

      public static double doubleValue(String aString)
      Returns an double value by parsing the given string.
    • doubleValue

      public static double doubleValue(String aString, int aStart)
      Returns an double value by parsing the given string starting at the given index.
    • getBytes

      public static byte[] getBytes(String aString)
      Returns the ASCII bytes of the given string (ISO-Latin).
    • getBytes

      public static byte[] getBytes(String aString, String enc)
      Returns the bytes of the given string in the requested char encoding.
    • getISOLatinString

      public static String getISOLatinString(byte[] bytes)
      Returns a string from the given ASCII bytes.
    • getISOLatinString

      public static String getISOLatinString(byte[] bytes, int offset, int length)
      Returns a string from the given ASCII bytes (from offset to offset+length).
    • indexOfIC

      public static int indexOfIC(String s1, String s2)
      Returns the index of search string s2 in given string s1, ignores case.
    • indexOfIC

      public static int indexOfIC(String s1, String s2, int start)
      Returns the index of search string s2 in given string s1, ignores case and starts at start char index.
    • equalsIC

      public static boolean equalsIC(String s1, String s2)
      Returns whether s1 equals s2, ignoring case.
    • endsWithIC

      public static boolean endsWithIC(String s1, String s2)
      Returns whether s1 ends with s2, ignoring case.
    • startsWithIC

      public static boolean startsWithIC(String s1, String s2)
      Returns whether s1 starts with s2, ignoring case.
    • firstCharUpperCase

      public static String firstCharUpperCase(String aString)
      Returns the given string with the first char promoted to uppercase.
    • firstCharLowerCase

      public static String firstCharLowerCase(String aString)
      Returns the given string with the first char demoted to lowercase.
    • wrap

      public static String wrap(String aString, int approximateWidth)
      Returns string wrapped to approximate width (quick and dirty line wrapping for use in things like option panes).
    • join

      public static String join(Object[] parts, String separator)
      Allows you to take an array of strings and concatenate them together with a separator
      Parameters:
      parts - an array of Strings
      separator - a string to place between elements
      Returns:
    • join

      public static String join(Object[] parts, String separator, int numElements)
      Allows you to take an array of strings and concatenate them together with a separator
      Parameters:
      parts - an array to be conacatenated
      separator - a string to place between elements
      numElements - how many to include in the result
      Returns: