org.equanda.util
Class StringUtil

java.lang.Object
  extended by org.equanda.util.StringUtil

public final class StringUtil
extends Object

string utility methods - format : build formatted strings, using the format descriptors as used by sprintf, but without the % - isNum : determine if a string contains only digits - trimRight

Author:
Joachim Van der Auwera

Method Summary
static String addPrefix(String format, String str)
           
static String digitsOnly(String str)
          Convert given string into a string which only contains the digits
static String format(double value, String format)
           
static String format(int value, String format)
           
static String format(long value, String format)
           
static String format(Object value, String format)
           
static String getLine(String str, int pos)
          Extract line with given number from the string, lines are separated by newlines.
static String increment(String base)
          Given a string, increment the digits at the end with one
static boolean isEmpty(String str)
          True when string is null or empty.
static boolean isNum(String s)
           
static String left(String base, int length)
          Return first x characters from a string, or less if string is not long enough
static String nospace(String str)
          Convert given string into a string which does not contain any of the whitespace (left/right and middle).
static boolean objectEquals(Object obj1, Object obj2)
           
static String replace(String base, String what, String with)
          In a string, replace all occurences of one string with another.
static String right(String base, int length)
          Return last x characters from a string, or less if string is not long enough
static String toCapitalizedCase(String str)
          Assure the passed string is all lower case exceptio for the first character which is upper case.
static String trimRight(String s)
          Removes white space (all ASCII control characters) from the right end of a string.
static String wordwrap(String base, int linelen, int line)
          Apply wordwrap to the given string, for given line length, and return the line requested.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

format

public static String format(Object value,
                            String format)

format

public static String format(int value,
                            String format)

format

public static String format(long value,
                            String format)

format

public static String format(double value,
                            String format)

isNum

public static boolean isNum(String s)

trimRight

public static String trimRight(String s)
Removes white space (all ASCII control characters) from the right end of a string.

Parameters:
s - input string
Returns:
this string, with white space removed from the end.

replace

public static String replace(String base,
                             String what,
                             String with)
In a string, replace all occurences of one string with another.

Parameters:
base - String to replace substrings in.
what - String to be found and replaced.
with - String to replaces occurences with.
Returns:
original with all replacements done.

wordwrap

public static String wordwrap(String base,
                              int linelen,
                              int line)
Apply wordwrap to the given string, for given line length, and return the line requested.

Parameters:
base - String which needs wordwrap
linelen - Line length to be used when wrapping
line - line which is requested
Returns:
selecting line taking wordwrap into account

digitsOnly

public static String digitsOnly(String str)
Convert given string into a string which only contains the digits

Parameters:
str - input string
Returns:
input with all non-digit characters removed

nospace

public static String nospace(String str)
Convert given string into a string which does not contain any of the whitespace (left/right and middle).

Parameters:
str - input string
Returns:
input with all whitespace characters removed

getLine

public static String getLine(String str,
                             int pos)
Extract line with given number from the string, lines are separated by newlines. 0 is the first line.

Parameters:
str - input string
pos - position
Returns:
requested line or empty string

addPrefix

public static String addPrefix(String format,
                               String str)

increment

public static String increment(String base)
Given a string, increment the digits at the end with one

Parameters:
base - input string
Returns:
incremented value with same prefix

objectEquals

public static boolean objectEquals(Object obj1,
                                   Object obj2)

left

public static String left(String base,
                          int length)
Return first x characters from a string, or less if string is not long enough

Parameters:
base - base string
length - mas number of characters to return
Returns:
limited string

right

public static String right(String base,
                           int length)
Return last x characters from a string, or less if string is not long enough

Parameters:
base - base string
length - mas number of characters to return
Returns:
limited string

isEmpty

public static boolean isEmpty(String str)
True when string is null or empty.

Parameters:
str - string to test
Returns:
true when string is null or empty

toCapitalizedCase

public static String toCapitalizedCase(String str)
Assure the passed string is all lower case exceptio for the first character which is upper case.

Parameters:
str - string to convert
Returns:
converted string


Copyright © 2007-2009. All Rights Reserved.