|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xnap.commons.util.StringHelper
public class StringHelper
Provides a set of static methods that help with string parsing and modifying.
Field Summary | |
---|---|
static String |
ALPHA_NUM
|
static String |
ALPHABET_LOWER
|
static String |
ALPHABET_UPPER
|
static String |
ANYTHING
|
static String |
EMAIL
|
static String |
HOST
|
static String |
MONEY_USD
|
static String |
NUMBERS_DECIMAL
|
static String |
NUMBERS_INT
|
static String |
REGULAR_STRING
|
static String[] |
SIZES
|
Constructor Summary | |
---|---|
StringHelper()
|
Method Summary | |
---|---|
static void |
append(StringBuffer sb,
String text,
int count)
Appends text to |
static String |
firstToken(String text,
String separator)
Splits text at the first occurence of separator
and returns the left part, excluding the separator. |
static String |
formatLength(long i)
Formats number of seconds in appropriate time unit |
static String |
formatSize(long size)
Returns value (byte) formatted as a file size. |
static int |
indexOfDigit(String s)
Returns the index of the first digit in s . |
static String |
lastPrefix(String text,
String separator)
Splits text at the last occurence of separator
and returns the left part, excluding the separator. |
static String |
lastToken(String text,
String separator)
Splits text at the last occurence of separator
and returns the right part, excluding the separator. |
static String |
pad(String text,
int padding)
Prepends and appends padding whitespaces to text and
returns the result. |
static String |
pad(String text,
int lpadding,
int rpadding)
Prepends lpadding and appends rpadding
whitespaces to text and returns the result. |
static String |
randomString(int length)
Returns a random lower case letter-only string with length
characters. |
static String |
replaceAll(String s,
String oldChars,
String newChars)
Replaces all occurences of oldChars in s by
newChars . |
static String |
stripExtra(String s)
Removes all characters from s that are not letters. |
static String[] |
toArray(String value,
String separators)
Uses a StringTokenizer to split value . |
static String |
toFirstUpper(String value)
Returns a new String that has the first letter of value
set to upper case. |
static int[] |
toIntArray(String value,
String separators)
|
static List<String> |
toList(String value,
String separators)
|
static String |
toString(byte[] data)
Tries to autodect encoding. |
static String |
toString(Collection c,
String separator)
|
static String |
toString(int[] array,
String separator)
|
static String |
toString(String[] array,
String separator)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String[] SIZES
public static final String ALPHABET_LOWER
public static final String ALPHABET_UPPER
public static final String NUMBERS_INT
public static final String NUMBERS_DECIMAL
public static final String MONEY_USD
public static final String ALPHA_NUM
public static final String EMAIL
public static final String HOST
public static final String REGULAR_STRING
public static final String ANYTHING
Constructor Detail |
---|
public StringHelper()
Method Detail |
---|
public static String firstToken(String text, String separator)
text
at the first occurence of separator
and returns the left part, excluding the separator.
text
- the haystackseparator
- the needle
public static int indexOfDigit(String s)
s
.
s
does not contain digits; the index of
the first digit, otherwiseString.indexOf(String)
public static String lastPrefix(String text, String separator)
text
at the last occurence of separator
and returns the left part, excluding the separator.
text
- the haystackseparator
- the needle
public static String lastToken(String text, String separator)
text
at the last occurence of separator
and returns the right part, excluding the separator.
text
- the haystackseparator
- the needle
public static String randomString(int length)
length
characters.
public static String replaceAll(String s, String oldChars, String newChars)
oldChars
in s
by
newChars
.
s
public static String stripExtra(String s)
s
that are not letters.
Returns a new String which can be for instance used as search text.
public static String[] toArray(String value, String separators)
StringTokenizer
to split value
.
value
- the String to splitseparators
- the separators
StringTokenizer
public static String toFirstUpper(String value)
String
that has the first letter of value
set to upper case.
public static int[] toIntArray(String value, String separators)
public static List<String> toList(String value, String separators)
public static String toString(byte[] data)
public static String toString(Collection c, String separator)
public static String toString(int[] array, String separator)
public static String toString(String[] array, String separator)
public static String formatSize(long size)
value
(byte) formatted as a file size.
For example value=2048 returns "2 kb".
size
- filesize to be formatted
public static String formatLength(long i)
i
- number of seconds
public static final String pad(String text, int padding)
padding
whitespaces to text and
returns the result.
text
- the textpadding
- the number of spaces to prepend and append
IllegalArgumentException
- if padding
< 0public static final String pad(String text, int lpadding, int rpadding)
lpadding
and appends rpadding
whitespaces to text and returns the result.
text
- the textlpadding
- the number of spaces to prependrpadding
- the number of spaces to append
IllegalArgumentException
- if lpadding
< 0 or
rpadding
< 0public static final void append(StringBuffer sb, String text, int count)
text to sb
count
times.
- Parameters:
sb
- the buffer the text is appended totext
- the textcount
- the number of times text is appenden to buffer
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |