|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.crosswire.common.util.StringUtil
public final class StringUtil
A generic class of String utils. It would be good if we could put this stuff in java.lang ...
for license details.
The copyright to this program is held by it's authors.
Field Summary | |
---|---|
static String[] |
EMPTY_STRING_ARRAY
An empty immutable String array. |
static String |
NEWLINE
The newline character |
Constructor Summary | |
---|---|
private |
StringUtil()
Prevent Instansiation |
Method Summary | |
---|---|
static String |
createTitle(String variable)
This function creates a readable title from a variable name type input. |
static String |
getInitials(String sentence)
For example getInitials("Java DataBase Connectivity") = "JDC" and getInitials("Church of England") = "CoE". |
static String |
join(Object[] array,
String aSeparator)
Joins the elements of the provided array into a single String containing the provided list of elements. |
static String |
read(Reader in)
This method reads an InputStream In its entirety, and passes The text back as a string. |
static String[] |
split(String str)
Splits the provided text into an array, using whitespace as the separator. |
static String[] |
split(String str,
char separatorChar)
Splits the provided text into an array, separator specified. |
static String[] |
split(String str,
String separatorChars)
Splits the provided text into an array, separators specified. |
static String[] |
split(String str,
String separatorChars,
int max)
Splits the provided text into an array, separators specified. |
static String[] |
splitAll(String str,
char separatorChar)
Splits the provided text into an array, separator specified. |
static String |
toString(Object[] a)
Returns a string representation of the contents of the specified array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String NEWLINE
public static final String[] EMPTY_STRING_ARRAY
String
array.
Constructor Detail |
---|
private StringUtil()
Method Detail |
---|
public static String read(Reader in) throws IOException
in
- The Stream to read from.
IOException
public static String createTitle(String variable)
public static String getInitials(String sentence)
sentence
- The phrase from which to get the initial letters.
public static String[] split(String str)
Splits the provided text into an array, using whitespace as the
separator.
Whitespace is defined by Character.isWhitespace(char)
.
The separator is not included in the returned String array. Adjacent separators are treated as one separator.
A null
input String returns null
.
StringUtils.split(null) = null StringUtils.split("") = [] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split(" abc ") = ["abc"]
str
- the String to parse, may be null
null
if null String inputpublic static String[] split(String str, char separatorChar)
Splits the provided text into an array, separator specified. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as one separator.
A null
input String returns null
.
StringUtils.split(null, *) = null StringUtils.split("", *) = [] StringUtils.split("a.b.c", '.') = ["a", "b", "c"] StringUtils.split("a..b.c", '.') = ["a", "b", "c"] StringUtils.split("a:b:c", '.') = ["a:b:c"] StringUtils.split("a\tb\nc", null) = ["a", "b", "c"] StringUtils.split("a b c", ' ') = ["a", "b", "c"]
str
- the String to parse, may be nullseparatorChar
- the character used as the delimiter,
null
splits on whitespace
public static String[] splitAll(String str, char separatorChar)
Splits the provided text into an array, separator specified. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated individually.
A null
input String returns null
.
StringUtils.split(null, *) = null StringUtils.split("", *) = [] StringUtils.split("a.b.c", '.') = ["a", "b", "c"] StringUtils.split("a..b.c", '.') = ["a", "b", "c"] StringUtils.split("a:b:c", '.') = ["a:b:c"] StringUtils.split("a\tb\nc", null) = ["a", "b", "c"] StringUtils.split("a b c", ' ') = ["a", "b", "c"]
str
- the String to parse, may be nullseparatorChar
- the character used as the delimiter,
null
splits on whitespace
public static String[] split(String str, String separatorChars)
Splits the provided text into an array, separators specified. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as one separator.
A null
input String returns null
.
A null
separatorChars splits on whitespace.
StringUtils.split(null, *) = null StringUtils.split("", *) = [] StringUtils.split("abc def", null) = ["abc", "def"] StringUtils.split("abc def", " ") = ["abc", "def"] StringUtils.split("abc def", " ") = ["abc", "def"] StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
str
- the String to parse, may be nullseparatorChars
- the characters used as the delimiters,
null
splits on whitespace
null
if null String inputpublic static String[] split(String str, String separatorChars, int max)
Splits the provided text into an array, separators specified. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as one separator.
A null
input String returns null
.
A null
separatorChars splits on whitespace.
StringUtils.split(null, *, *) = null StringUtils.split("", *, *) = [] StringUtils.split("ab de fg", null, 0) = ["ab", "cd", "ef"] StringUtils.split("ab de fg", null, 0) = ["ab", "cd", "ef"] StringUtils.split("ab:cd:ef", ":", 0) = ["ab", "cd", "ef"] StringUtils.split("ab:cd:ef", ":", 2) = ["ab", "cdef"]
str
- the String to parse, may be nullseparatorChars
- the characters used as the delimiters,
null
splits on whitespacemax
- the maximum number of elements to include in the
array. A zero or negative value implies no limit
public static String join(Object[] array, String aSeparator)
Joins the elements of the provided array into a single String containing the provided list of elements.
No delimiter is added before or after the list.
A null
separator is the same as an empty String ("").
Null objects or empty strings within the array are represented by
empty strings.
StringUtils.join(null, *) = null StringUtils.join([], *) = "" StringUtils.join([null], *) = "" StringUtils.join(["a", "b", "c"], "--") = "a--b--c" StringUtils.join(["a", "b", "c"], null) = "abc" StringUtils.join(["a", "b", "c"], "") = "abc" StringUtils.join([null, "", "a"], ',') = ",,a"
array
- the array of values to join together, may be nullaSeparator
- the separator character to use, null treated as ""
null
if null array inputpublic static String toString(Object[] a)
Object.toString()
method inherited from
Object, which describes their identities rather than
their contents.
The value returned by this method is equal to the value that would be returned by Arrays.asList(a).toString(), unless a is null, in which case "null" is returned.
This is borrowed from Java 1.5, but uses StringBuffer.
a
- the array whose string representation to return
|
Copyright ยจ 2003-2007 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |