class StringManipulator extends Object
Modifier and Type | Class and Description |
---|---|
static class |
StringManipulator.Token
Inner class for representing a token
|
Modifier and Type | Field and Description |
---|---|
private static String |
defaultRegexDelim
default regex delimiter pattern
|
Constructor and Description |
---|
StringManipulator() |
Modifier and Type | Method and Description |
---|---|
static String |
abbreviate(String s)
Abbreviate a specified string, by keeping only the first letter
of each word.
|
static String |
centerJustify(Object o,
int width)
Center-justify the string representation of a given object, padding with
leading and trailing spaces so that its length is at least the specified
width.
|
static String |
deleteExtraWhitespace(String s)
Delete extra whitespace in a specified string, by replacing contiguous
whitespace characters with a single space.
|
static String |
deletePunctuation(String s)
Delete punctuation in a specified string, by deleting all punctuation
characters.
|
static String |
deleteWhitespace(String s)
Delete whitespace in a specified string, by deleting all whitespace
characters.
|
static String |
formattedDouble(double n)
Return a formatted string representation of a given double number
(format is locale-sensitive).
|
static String |
formattedLong(long n)
Return a formatted string representation of a given long number
(format is locale-sensitive).
|
static String |
leftJustify(Object o,
int width)
Left-justify the string representation of a given object, padding with
trailing spaces so that its length is at least the specified width.
|
static String |
leftTrim(String s)
Trim away whitespace on the left.
|
private static int |
normalizeIndex(int len,
int index)
Normalize user-specified index value.
|
static String |
repeat(Object o,
int n)
Repeat the string representation of a given object, a specified number
of times.
|
static String |
reverse(String s)
Reverse the string.
|
static String |
rightJustify(Object o,
int width)
Right-justify the string representation of a given object, padding with
leading spaces so that its length is at least the specified width.
|
static String |
rightTrim(String s)
Trim away whitespace on the right.
|
static String |
spaceOutWords(String s)
Space out words in a specified string, by inserting a single space
between concatenated words.
|
static String |
substring(String in,
String format,
char rangeChar,
char delimChar)
Extract a substring from a given string, according to the specified
format.
|
static String |
swapCase(String s)
Swap the case of a specified string, by converting lower case
characters to upper case and vice versa.
|
static StringManipulator.Token[] |
tokenize(String in,
String regexDelim,
boolean includeDelimiters)
Tokenize the given string, using the specified regex delimiter pattern.
|
static String |
toTitleCase(String s)
Convert a specified string to title case, by capitalizing only the
first letter of each word.
|
private static final String defaultRegexDelim
StringManipulator()
public static StringManipulator.Token[] tokenize(String in, String regexDelim, boolean includeDelimiters)
in
- String to be tokenizedregexDelim
- Regex delimiter patternincludeDelim
- If true, then delimiter tokens are returned too;
otherwise, only non-delimiter tokens are returnedpublic static String substring(String in, String format, char rangeChar, char delimChar)
in
- String from which the substring is to be extractedformat
- Format string describing the sequence of characters in the substringrangeChar
- Range character to be useddelimChar
- Delimiter character to be usedprivate static int normalizeIndex(int len, int index)
len
- Length of the source stringindex
- User-specified index valuepublic static String formattedLong(long n)
n
- Long number to be formattedpublic static String formattedDouble(double n)
n
- Double number to be formattedpublic static String centerJustify(Object o, int width)
o
- Object to be center-justifiedwidth
- Width of the resulting center-justified stringpublic static String leftJustify(Object o, int width)
o
- Object for to be left-justifiedwidth
- Width of the resulting left-justified stringpublic static String rightJustify(Object o, int width)
o
- Object to be right-justifiedwidth
- Width of the resulting right-justified stringpublic static String repeat(Object o, int n)
o
- Object to be repeatedn
- Number of times to repeatpublic static String toTitleCase(String s)
s
- Input stringpublic static String abbreviate(String s)
s
- Input stringpublic static String reverse(String s)
s
- Input stringpublic static String leftTrim(String s)
s
- Input stringpublic static String rightTrim(String s)
s
- Input stringpublic static String deleteExtraWhitespace(String s)
s
- Input stringpublic static String deleteWhitespace(String s)
s
- Input stringpublic static String deletePunctuation(String s)
s
- Input stringpublic static String spaceOutWords(String s)
s
- Input stringWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses