public class StringUtil
extends Object
Modifier and Type | Field and Description |
---|---|
protected static char[] |
HEX_DIGITS |
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
add(String s,
String add)
Adds string
add to string s resulting in a
comma delimited list of strings, disallowing duplicate strings in the
list. |
static String |
add(String s,
String add,
String delimiter)
Adds string
add to string s that represents a
delimited list of strings, using a specified delimiter and disallowing
duplicate words. |
static String |
add(String s,
String add,
String delimiter,
boolean allowDuplicates)
Adds string
add to string s that represents a
delimited list of strings, using a specified delimiter and optionally
allowing duplicate words. |
static String |
appendParentheticalSuffix(String s,
int suffix)
Returns the original string with an appended space followed by the string
value of the suffix surrounded by parentheses.
|
static String |
appendParentheticalSuffix(String s,
String suffix)
Returns the original string with an appended space followed by the suffix
surrounded by parentheses.
|
static String |
bytesToHexString(byte[] bytes)
Converts an array of bytes to a string representing the bytes in
hexadecimal form.
|
static boolean |
contains(String s,
String text)
Returns
true if the string contains the text as one or more
consecutive comma delimited list entries. |
static boolean |
contains(String s,
String text,
String delimiter)
Returns
true if the string contains the text as one or more
consecutive delimited list entries. |
static boolean |
containsIgnoreCase(String s,
String text)
Returns
true if the string contains the text as one or more
consecutive comma delimited list entries, ignoring case. |
static boolean |
containsIgnoreCase(String s,
String text,
String delimiter)
Returns
true if the string contains the text as one or more
consecutive delimited list entries, ignoring case. |
static int |
count(String s,
char c) |
static int |
count(String s,
int start,
int end,
char c) |
static int |
count(String s,
int start,
int end,
String text) |
static int |
count(String s,
String text)
Returns the number of times the text appears in the string.
|
static boolean |
endsWith(String s,
char end)
Returns
true if the string ends with the specified
character, ignoring case. |
static boolean |
endsWith(String s,
String end)
Returns
true if the string ends with the string
end , ignoring case. |
static boolean |
equals(String s1,
String s2)
Returns
true if the strings are equal. |
static boolean |
equalsIgnoreBreakLine(String s1,
String s2)
Returns
true if the strings are equal, ignoring new line
characters. |
static boolean |
equalsIgnoreCase(char c1,
char c2) |
static boolean |
equalsIgnoreCase(String s1,
String s2)
Returns
true if the strings are equal, ignoring case. |
static String |
extract(String s,
char[] chars)
Deprecated.
As of Judson (7.1.x), with no direct replacement
|
static String |
extractChars(String s)
Returns the substring of English characters from the string.
|
static String |
extractDigits(String s)
Returns a string consisting of all of the digits extracted from the
string.
|
static String |
extractFirst(String s,
char delimiter)
Returns the substring of
s up to but not including the first
occurrence of the delimiter. |
static String |
extractFirst(String s,
String delimiter)
Returns the substring of
s up to but not including the first
occurrence of the delimiter. |
static String |
extractLast(String s,
char delimiter)
Returns the substring of
s after but not including the last
occurrence of the delimiter. |
static String |
extractLast(String s,
String delimiter)
Returns the substring of
s after but not including the last
occurrence of the delimiter. |
static String |
extractLeadingDigits(String s)
Returns the substring of all leading digits of string
s , or
an empty string if it has no leading digits. |
static String |
highlight(String s,
String[] queryTerms)
Deprecated.
As of Wilberforce (7.0.x), moved to
HighlightUtil.highlight(String, String[]) } |
static String |
highlight(String s,
String[] queryTerms,
String highlight1,
String highlight2)
Deprecated.
As of Wilberforce (7.0.x), moved to
HighlightUtil.highlight(String, String[], String, String) } |
static int |
indexOfAny(String s,
char[] chars)
Returns the index within the string of the first occurrence of any
character from the array.
|
static int |
indexOfAny(String s,
char[] chars,
int fromIndex)
Returns the index within the string of the first occurrence of any
character from the array, starting the search at the specified index
within the string.
|
static int |
indexOfAny(String s,
char[] chars,
int fromIndex,
int toIndex)
Returns the index within the string of the first occurrence of any
character from the array, up to and including the specified end index
within the string, starting the search at the specified start index
within the string.
|
static int |
indexOfAny(String s,
String[] texts)
Returns the index within the string of the first occurrence of any string
from the array.
|
static int |
indexOfAny(String s,
String[] texts,
int fromIndex)
Returns the index within the string of the first occurrence of any string
from the array, starting the search at the specified index within the
string.
|
static int |
indexOfAny(String s,
String[] texts,
int fromIndex,
int toIndex)
Returns the index within the string of the first occurrence of any string
from the array, up to and including the specified end index within the
string, starting the search at the specified start index within the
string.
|
static String |
insert(String s,
String insert,
int offset)
Inserts one string into the other at the specified offset index.
|
static boolean |
isLowerCase(String s)
Returns
true if all the characters in string s
are lower case, ignoring any non-alphabetic characters. |
static boolean |
isUpperCase(String s)
Returns
true if all the characters in string s
are upper case, ignoring any non-alphabetic characters. |
static int |
lastIndexOfAny(String s,
char[] chars)
Returns the index within the string of the last occurrence of any
character from the array.
|
static int |
lastIndexOfAny(String s,
char[] chars,
int toIndex)
Returns the index within the string of the last occurrence of any
character from the array, starting the search at the specified index
within the string.
|
static int |
lastIndexOfAny(String s,
char[] chars,
int fromIndex,
int toIndex)
Returns the index within the string of the last occurrence of any
character from the array, up to and including the specified end index
within the string, starting the search at the specified start index
within the string.
|
static int |
lastIndexOfAny(String s,
String[] texts)
Returns the index within the string of the last occurrence of any string
from the array.
|
static int |
lastIndexOfAny(String s,
String[] texts,
int toIndex)
Returns the index within the string of the last occurrence of any string
from the array, starting the search at the specified index within the
string.
|
static int |
lastIndexOfAny(String s,
String[] texts,
int fromIndex,
int toIndex)
Returns the index within the string of the last occurrence of any string
from the array, up to and including the specified end index within the
string, starting the search at the specified start index within the
string.
|
static void |
lowerCase(String... array)
Converts all of the characters in the arbitrary number of strings to
lower case.
|
static String |
lowerCase(String s)
Converts all of the characters in the string to lower case.
|
static String |
lowerCaseFirstLetter(String s)
Converts the first character of the string to lower case.
|
static boolean |
matches(String s,
String pattern)
Returns
true if the specified pattern occurs at any position
in the string. |
static boolean |
matchesIgnoreCase(String s,
String pattern)
Returns
true if the specified pattern occurs at any position
in the string, ignoring case. |
static String |
merge(boolean[] array)
Merges the elements of the boolean array into a string representing a
comma delimited list of its values.
|
static String |
merge(boolean[] array,
String delimiter)
Merges the elements of the boolean array into a string representing a
delimited list of its values.
|
static String |
merge(char[] array)
Merges the elements of the character array into a string representing a
comma delimited list of its values.
|
static String |
merge(char[] array,
String delimiter)
Merges the elements of the character array into a string representing a
delimited list of its values.
|
static String |
merge(Collection<?> col)
Merges the elements of the collection by returning a string representing
a comma delimited list of its values.
|
static String |
merge(Collection<?> col,
String delimiter)
Merges the elements of the collection by returning a string representing
a delimited list of its values.
|
static String |
merge(double[] array)
Merges the elements of an array of double-precision decimal numbers by
returning a string representing a comma delimited list of its values.
|
static String |
merge(double[] array,
String delimiter)
Merges the elements of an array of double-precision decimal numbers by
returning a string representing a delimited list of its values.
|
static String |
merge(float[] array)
Merges the elements of an array of decimal numbers into a string
representing a comma delimited list of its values.
|
static String |
merge(float[] array,
String delimiter)
Merges the elements of an array of decimal numbers into a string
representing a delimited list of its values.
|
static String |
merge(int[] array)
Merges the elements of an array of integers into a string representing a
comma delimited list of its values.
|
static String |
merge(int[] array,
String delimiter)
Merges the elements of an array of integers into a string representing a
delimited list of its values.
|
static String |
merge(long[] array)
Merges the elements of an array of long integers by returning a string
representing a comma delimited list of its values.
|
static String |
merge(long[] array,
String delimiter)
Merges the elements of an array of long integers by returning a string
representing a delimited list of its values.
|
static String |
merge(Object[] array)
Merges the elements of an array of objects into a string representing a
comma delimited list of the objects.
|
static String |
merge(Object[] array,
String delimiter)
Merges the elements of an array of objects into a string representing a
delimited list of the objects.
|
static String |
merge(short[] array)
Merges the elements of an array of short integers by returning a string
representing a comma delimited list of its values.
|
static String |
merge(short[] array,
String delimiter)
Merges the elements of an array of short integers by returning a string
representing a delimited list of its values.
|
static String |
quote(String s)
Returns the string enclosed by apostrophes.
|
static String |
quote(String s,
char quote)
Returns the string enclosed by the quote character.
|
static String |
quote(String s,
String quote)
Returns the string enclosed by the quote strings.
|
static String |
randomId()
Returns a randomized string of four lower case, alphabetic characters.
|
static String |
randomize(String s)
Deprecated.
As of Judson (7.1.x), replaced by
RandomUtil.shuffle(String) |
static String |
randomString()
Returns a randomized string of eight characters consisting of lower case
letters, upper case letters, and single-digit whole numbers.
|
static String |
randomString(int length)
Returns a randomized string of the specified length consisting of lower
case letters, upper case letters, and single-digit whole numbers.
|
static String |
read(Class<?> clazz,
String name) |
static String |
read(ClassLoader classLoader,
String name) |
static String |
read(ClassLoader classLoader,
String name,
boolean all) |
static String |
read(InputStream is) |
static void |
readLines(InputStream is,
Collection<String> lines) |
static String |
remove(String s,
String element)
Deprecated.
As of Wilberforce (7.0.x), replaced by
removeFromList(String, String) |
static String |
remove(String s,
String element,
String delimiter)
Deprecated.
As of Wilberforce (7.0.x), replaced by
removeFromList(String, String, String) |
static String |
removeChar(String s,
char oldSub) |
static String |
removeChars(String s,
char... oldSubs) |
static String |
removeFromList(String s,
String element)
Removes the
remove string from string s that
represents a list of comma delimited strings. |
static String |
removeFromList(String s,
String element,
String delimiter)
Removes the
remove string from string s that
represents a list of delimited strings. |
static String |
removeSubstring(String s,
String oldSub) |
static String |
removeSubstrings(String s,
String... oldSubs) |
static String |
replace(String s,
char[] oldSubs,
char[] newSubs) |
static String |
replace(String s,
char[] oldSubs,
String[] newSubs) |
static String |
replace(String s,
char oldSub,
char newSub)
Replaces all occurrences of the character with the new character.
|
static String |
replace(String s,
char oldSub,
String newSub)
Replaces all occurrences of the character with the new string.
|
static String |
replace(String s,
String[] oldSubs,
String[] newSubs)
Replaces all occurrences of the elements of the string array with the
corresponding elements of the new string array.
|
static String |
replace(String s,
String[] oldSubs,
String[] newSubs,
boolean exactMatch)
Replaces all occurrences of the elements of the string array with the
corresponding elements of the new string array, optionally replacing only
substrings that are surrounded by word boundaries.
|
static String |
replace(String s,
String oldSub,
String newSub)
Replaces all occurrences of the string with the new string.
|
static String |
replace(String s,
String oldSub,
String newSub,
int fromIndex)
Replaces all occurrences of the string with the new string, starting from
the specified index.
|
static String |
replace(String s,
String begin,
String end,
Map<String,String> values)
Replaces all occurrences of the keywords found in the substring, defined
by the beginning and ending strings, with the new values.
|
static String |
replaceFirst(String s,
char oldSub,
char newSub)
Replaces the first occurrence of the character with the new character.
|
static String |
replaceFirst(String s,
char oldSub,
String newSub)
Replaces the first occurrence of the character with the new string.
|
static String |
replaceFirst(String s,
String[] oldSubs,
String[] newSubs)
Replaces the first occurrences of the elements of the string array with
the corresponding elements of the new string array.
|
static String |
replaceFirst(String s,
String oldSub,
String newSub)
Replaces the first occurrence of the string with the new string.
|
static String |
replaceFirst(String s,
String oldSub,
String newSub,
int fromIndex)
Replaces the first occurrences of the elements of the string array with
the corresponding elements of the new string array, beginning the element
search from the index position.
|
static String |
replaceLast(String s,
char oldSub,
char newSub)
Replaces the last occurrence of the character with the new character.
|
static String |
replaceLast(String s,
char oldSub,
String newSub)
Replaces the last occurrence of the character with the new string.
|
static String |
replaceLast(String s,
String[] oldSubs,
String[] newSubs)
Replaces the last occurrences of the elements of the string array with
the corresponding elements of the new string array.
|
static String |
replaceLast(String s,
String oldSub,
String newSub)
Replaces the last occurrence of the string
oldSub in the
string s with the string newSub . |
static StringBundler |
replaceToStringBundler(String s,
String begin,
String end,
Map<String,String> values)
Replaces all occurrences of the keywords found in the substring, defined
by the beginning and ending strings, with the new values.
|
static StringBundler |
replaceWithStringBundler(String s,
String begin,
String end,
Map<String,StringBundler> values)
Replaces all occurrences of the keywords found in the substring, defined
by the beginning and ending strings, with the new values.
|
static String |
reverse(String s)
Deprecated.
As of Judson (7.1.x), with no direct replacement
|
static String |
safePath(String path)
Deprecated.
As of Judson (7.1.x), with no direct replacement
|
static String |
shorten(String s)
Returns a string representing the original string appended with suffix
"..." and then shortened to 20 characters.
|
static String |
shorten(String s,
int length)
Returns a string representing the original string appended with suffix
"..." and then shortened to the specified length.
|
static String |
shorten(String s,
int length,
String suffix)
Returns a string representing the original string appended with the
specified suffix and then shortened to the specified length.
|
static String |
shorten(String s,
String suffix)
Returns a string representing the original string appended with the
specified suffix and then shortened to 20 characters.
|
static String[] |
split(String s)
Splits string
s around comma characters. |
static boolean[] |
split(String s,
boolean x)
Splits the string
s around comma characters returning the
boolean values of the substrings. |
static String[] |
split(String s,
char delimiter)
Splits the string
s around the specified delimiter. |
static double[] |
split(String s,
double x)
Splits the string
s around comma characters returning the
double-precision decimal values of the substrings. |
static float[] |
split(String s,
float x)
Splits the string
s around comma characters returning the
decimal values of the substrings. |
static int[] |
split(String s,
int x)
Splits the string
s around comma characters returning the
integer values of the substrings. |
static long[] |
split(String s,
long x)
Splits the string
s around comma characters returning the
long integer values of the substrings. |
static short[] |
split(String s,
short x)
Splits the string
s around comma characters returning the
short integer values of the substrings. |
static String[] |
split(String s,
String delimiter)
Splits the string
s around the specified delimiter string. |
static boolean[] |
split(String s,
String delimiter,
boolean x)
Splits the string
s around the specified delimiter returning
the boolean values of the substrings. |
static double[] |
split(String s,
String delimiter,
double x)
Splits the string
s around the specified delimiter returning
the double-precision decimal values of the substrings. |
static float[] |
split(String s,
String delimiter,
float x)
Splits the string
s around the specified delimiter returning
the decimal values of the substrings. |
static int[] |
split(String s,
String delimiter,
int x)
Splits the string
s around the specified delimiter returning
the integer values of the substrings. |
static long[] |
split(String s,
String delimiter,
long x)
Splits the string
s around the specified delimiter returning
the long integer values of the substrings. |
static short[] |
split(String s,
String delimiter,
short x)
Splits the string
s around the specified delimiter returning
the short integer values of the substrings. |
static String[] |
splitLines(String s)
Splits string
s around return and newline characters. |
static boolean |
startsWith(String s,
char begin)
Returns
true if, ignoring case, the string starts with the
specified character. |
static boolean |
startsWith(String s,
String start)
Returns
true if, ignoring case, the string starts with the
specified start string. |
static int |
startsWithWeight(String s1,
String s2)
Returns the number of starting characters that
s1 and
s2 have in common before their characters deviate. |
static String |
strip(String s,
char remove)
Deprecated.
As of Judson (7.1.x), replaced by
removeChar(String,
char) |
static String |
strip(String s,
char[] remove)
Deprecated.
As of Judson (7.1.x), replaced by
removeChars(String,
char...) |
static String |
stripBetween(String s,
String begin,
String end)
Returns a string representing the combination of the substring of
s up to but not including the string begin
concatenated with the substring of s after but not including
the string end . |
static String |
stripCDATA(String s)
Returns a string representing the string
s with its
<! |
static String |
stripParentheticalSuffix(String s)
Returns a string representing the string
s without an
appended parenthetical suffix. |
static String |
toCharCode(String s)
Returns a string representing the Unicode character codes of the
characters comprising the string
s . |
static String |
toHexString(int i)
Returns a string representing the hexidecimal character code of the
integer.
|
static String |
toHexString(long l)
Returns a string representing the hexidecimal character code of the long
integer.
|
static String |
toHexString(Object obj)
Returns a string representing the hexidecimal character code of the
Integer or Long object type. |
static String |
toLowerCase(String s)
Converts all of the characters in the string to lower case, based on the
portal instance's default locale.
|
static String |
toLowerCase(String s,
Locale locale)
Converts all of the characters in the string to lower case, based on the
locale.
|
static String |
toUpperCase(String s)
Converts all of the characters in the string to upper case, based on the
portal instance's default locale.
|
static String |
toUpperCase(String s,
Locale locale)
Converts all of the characters in the string to upper case, based on the
locale.
|
static String |
trim(String s)
Trims all leading and trailing whitespace from the string.
|
static String |
trim(String s,
char c)
Trims leading and trailing whitespace from the string, up to but not
including the whitespace character specified by
c . |
static String |
trim(String s,
char[] exceptions)
Trims leading and trailing whitespace from the string, up to but not
including the whitespace characters specified by
exceptions . |
static String |
trimLeading(String s)
Trims all leading whitespace from the string.
|
static String |
trimLeading(String s,
char c)
Trims leading whitespace from the string, up to but not including the
whitespace character specified by
c . |
static String |
trimLeading(String s,
char[] exceptions)
Trims leading whitespace from the string, up to but not including the
whitespace characters specified by
exceptions . |
static String |
trimTrailing(String s)
Trims all trailing whitespace from the string.
|
static String |
trimTrailing(String s,
char c)
Trims trailing whitespace from the string, up to but not including the
whitespace character specified by
c . |
static String |
trimTrailing(String s,
char[] exceptions)
Trims trailing whitespace from the string, up to but not including the
whitespace characters specified by
exceptions . |
static String |
unquote(String s)
Removes leading and trailing double and single quotation marks from the
string.
|
static String |
upperCase(String s)
Converts all of the characters in the string to upper case.
|
static String |
upperCaseFirstLetter(String s)
Converts the first character of the string to upper case.
|
static String |
valueOf(Object obj)
Deprecated.
As of Judson (7.1.x), with no direct replacement
|
static boolean |
wildcardMatches(String s,
String wildcard,
char singleWildcardCharacter,
char multipleWildcardCharacter,
char escapeWildcardCharacter,
boolean caseSensitive)
Returns
true if the string matches the wildcard pattern. |
static String |
wrap(String text)
Deprecated.
As of Judson (7.1.x), with no direct replacement
|
static String |
wrap(String text,
int width,
String lineSeparator)
Deprecated.
As of Judson (7.1.x), with no direct replacement
|
public static String add(String s, String add)
add
to string s
resulting in a
comma delimited list of strings, disallowing duplicate strings in the
list.
The resulting string ends with a comma even if the original string does not.
s
- the original string, representing a comma delimited list of
stringsadd
- the string to add to the original, representing the string to
add to the listnull
if the string to add
is null
public static String add(String s, String add, String delimiter)
add
to string s
that represents a
delimited list of strings, using a specified delimiter and disallowing
duplicate words.
The returned string ends with the delimiter even if the original string does not.
s
- the original string, representing a delimited list of stringsadd
- the string to add to the original, representing the string to
add to the listdelimiter
- the delimiter used to separate strings in the listnull
if the string to
add or the delimiter string is null
public static String add(String s, String add, String delimiter, boolean allowDuplicates)
add
to string s
that represents a
delimited list of strings, using a specified delimiter and optionally
allowing duplicate words.
The returned string ends with the delimiter even if the original string does not.
s
- the original string, representing a delimited list of stringsadd
- the string to add to the original, representing the string to
add to the listdelimiter
- the delimiter used to separate strings in the listallowDuplicates
- whether to allow duplicate stringsnull
if the string to
add or the delimiter string is null
public static String appendParentheticalSuffix(String s, int suffix)
If the original string ends with a numerical parenthetical suffix having
an integer value equal to suffix - 1
, then the existing
parenthetical suffix is replaced by the new one.
Examples:
appendParentheticalSuffix("file", 0) returns "file (0)"
appendParentheticalSuffix("file (0)", 0) returns "file (0) (0)"
appendParentheticalSuffix("file (0)", 1) returns "file (1)"
appendParentheticalSuffix("file (0)", 2) returns "file (0) (2)"
s
- the original stringsuffix
- the suffix to be appendedpublic static String appendParentheticalSuffix(String s, String suffix)
Example:
appendParentheticalSuffix("Java", "EE") returns "Java (EE)"
s
- the original stringsuffix
- the suffix to be appendedpublic static String bytesToHexString(byte[] bytes)
bytes
- the array of bytes to be convertedpublic static boolean contains(String s, String text)
true
if the string contains the text as one or more
consecutive comma delimited list entries.
Examples:
contains("one,two,three", "two") returns true
contains("one,two,three", "thr") returns false
contains("one,two,three", "one,two") returns true
s
- the string in which to searchtext
- the text to search for in the stringtrue
if the string contains the text as one or more
consecutive comma delimited list entries; false
otherwisepublic static boolean contains(String s, String text, String delimiter)
true
if the string contains the text as one or more
consecutive delimited list entries.
Examples:
contains("three...two...one", "two", "...") returns true
contains("three...two...one", "thr", "...") returns false
contains("three...two...one", "two...one", "...") returns true
s
- the string in which to searchtext
- the text to search for in the stringdelimiter
- the delimitertrue
if the string contains the text as one or more
consecutive delimited list entries; false
otherwisepublic static boolean containsIgnoreCase(String s, String text)
true
if the string contains the text as one or more
consecutive comma delimited list entries, ignoring case.
Examples:
containsIgnoreCase("one,two,three", "Two") returns true
containsIgnoreCase("one,two,three", "thr") returns false
containsIgnoreCase("one,two,three", "one,two") returns true
s
- the string in which to searchtext
- the text to search for in the stringtrue
if the string contains the text as one or more
consecutive comma delimited list entries; false
otherwisepublic static boolean containsIgnoreCase(String s, String text, String delimiter)
true
if the string contains the text as one or more
consecutive delimited list entries, ignoring case.
Examples:
containsIgnoreCase("three...two...one", "Two", "...") returns true
containsIgnoreCase("three...two...one", "thr", "...") returns false
containsIgnoreCase("three...two...one", "two...one", "...") returns true
s
- the string in which to searchtext
- the text to search for in the stringdelimiter
- the delimitertrue
if the string contains the text as one or more
consecutive delimited list entries; false
otherwisepublic static int count(String s, char c)
public static int count(String s, int start, int end, char c)
public static int count(String s, int start, int end, String text)
public static int count(String s, String text)
s
- the string in which to searchtext
- the text to search for in the stringpublic static boolean endsWith(String s, char end)
true
if the string ends with the specified
character, ignoring case.s
- the string in which to searchend
- the character to search for at the end of the stringtrue
if the string ends with the specified
character, ignoring case; false
otherwisepublic static boolean endsWith(String s, String end)
true
if the string ends with the string
end
, ignoring case.s
- the string in which to searchend
- the string to check for at the end of the stringtrue
if the string ends with the string
end
, ignoring case; false
otherwisepublic static boolean equals(String s1, String s2)
true
if the strings are equal.s1
- the first string to compares2
- the second string to comparetrue
if the strings are equal; false
otherwisepublic static boolean equalsIgnoreBreakLine(String s1, String s2)
true
if the strings are equal, ignoring new line
characters.s1
- the first string to compares2
- the second string to comparetrue
if the strings are equal, ignoring new line
characters; false
otherwisepublic static boolean equalsIgnoreCase(char c1, char c2)
public static boolean equalsIgnoreCase(String s1, String s2)
true
if the strings are equal, ignoring case.s1
- the first string to compares2
- the second string to comparetrue
if the strings are equal, ignoring case;
false
otherwise@Deprecated public static String extract(String s, char[] chars)
s
that is found in the character array chars
. The substring of
characters returned maintain their original order.s
- the string from which to extract characterschars
- the characters to extract from the strings
that is found in the character array
chars
, or an empty string if the given string is
null
public static String extractChars(String s)
s
- the string from which to extract charactersnull
public static String extractDigits(String s)
s
- the string from which to extract digitspublic static String extractFirst(String s, char delimiter)
s
up to but not including the first
occurrence of the delimiter.s
- the string from which to extract a substringdelimiter
- the character whose index in the string marks where to
end the substrings
up to but not including the first
occurrence of the delimiter, null
if the string is
null
or the delimiter does not occur in the stringpublic static String extractFirst(String s, String delimiter)
s
up to but not including the first
occurrence of the delimiter.s
- the string from which to extract a substringdelimiter
- the smaller string whose index in the larger string
marks where to end the substrings
up to but not including the first
occurrence of the delimiter, null
if the string is
null
or the delimiter does not occur in the stringpublic static String extractLast(String s, char delimiter)
s
after but not including the last
occurrence of the delimiter.s
- the string from which to extract the substringdelimiter
- the character whose last index in the string marks
where to begin the substrings
after but not including the last
occurrence of the delimiter, null
if the string is
null
or the delimiter does not occur in the stringpublic static String extractLast(String s, String delimiter)
s
after but not including the last
occurrence of the delimiter.s
- the string from which to extract the substringdelimiter
- the string whose last index in the string marks where
to begin the substrings
after but not including the last
occurrence of the delimiter, null
if the string is
null
or the delimiter does not occur in the stringpublic static String extractLeadingDigits(String s)
s
, or
an empty string if it has no leading digits.s
- the string from which to extract the substrings
, or
an empty string if it has no leading digits@Deprecated public static String highlight(String s, String[] queryTerms)
HighlightUtil.highlight(String, String[])
}@Deprecated public static String highlight(String s, String[] queryTerms, String highlight1, String highlight2)
HighlightUtil.highlight(String, String[], String, String)
}public static int indexOfAny(String s, char[] chars)
A null
string returns -1
. A null
or empty array returns -1
.
Examples:
indexOfAny(null, *) returns -1
indexOfAny(*, null) returns -1
indexOfAny(*, []) returns -1
indexOfAny("zzabyycdxx", ['a','c']) returns 2
indexOfAny("zzabyycdxx", ['c','a']) returns 2
indexOfAny("zzabyycdxx", ['m','n']) returns -1
s
- the string to search (optionally null
)chars
- the characters to search for (optionally null
)-1
if none of the
characters occurpublic static int indexOfAny(String s, char[] chars, int fromIndex)
A null
string returns -1
. A null
or empty array returns -1
.
Examples:
indexOfAny(null, *, *) returns -1
indexOfAny(*, null, *) returns -1
indexOfAny(*, [], *) returns -1
indexOfAny("zzabyycdxx", ['a','c'], 3) returns 6
s
- the string to search (optionally null
)chars
- the characters to search for (optionally null
)fromIndex
- the start index within the string-1
if none of the
characters occurpublic static int indexOfAny(String s, char[] chars, int fromIndex, int toIndex)
A null
string returns -1
. A null
or empty array returns -1
.
Examples:
indexOfAny(null, *, *, *) returns -1
indexOfAny(*, null, *, *) returns -1
indexOfAny(*, [], *, *) returns -1
indexOfAny("zzabyycdxx", ['a','c'], 3, 7) returns 6
s
- the string to search (optionally null
)chars
- the characters to search for (optionally null
)fromIndex
- the start index within the stringtoIndex
- the end index within the string-1
if none of the
characters occurpublic static int indexOfAny(String s, String[] texts)
A null
string returns -1
. A null
or empty array returns -1
, but an array containing
""
returns 0
if the string is not
null
.
Examples:
indexOfAny(null, *) returns -1
indexOfAny(*, null) returns -1
indexOfAny(*, [null]) returns -1
indexOfAny(*, []) returns -1
indexOfAny("zzabyycdxx", ["ab","cd"]) returns 2
indexOfAny("zzabyycdxx", ["cd","ab"]) returns 2
indexOfAny("zzabyycdxx", ["mn","op"]) returns -1
indexOfAny("zzabyycdxx", ["mn",""]) returns 0
s
- the string (optionally null
)texts
- the strings to search for (optionally null
)0
if the search array contains
""
, or -1
if none of the strings occurpublic static int indexOfAny(String s, String[] texts, int fromIndex)
A null
string returns -1
. A null
or empty array returns -1
, but an array containing
""
returns the specified start index if the string is not
null
.
Examples:
indexOfAny(null, *, *) returns -1
indexOfAny(*, null, *) returns -1
indexOfAny(*, [null], *) returns -1
indexOfAny(*, [], *) returns -1
indexOfAny("zzabyycdxx", ["ab","cd"], 3) returns 6
indexOfAny("zzabyycdxx", ["cd","ab"], 3) returns 6
indexOfAny("zzabyycdxx", ["mn","op"], *) returns -1
indexOfAny("zzabyycdxx", ["mn",""], 3) returns 3
s
- the string to search (optionally null
)texts
- the strings to search for (optionally null
)fromIndex
- the start index within the string""
, or -1
if none of the strings occurpublic static int indexOfAny(String s, String[] texts, int fromIndex, int toIndex)
A null
string returns -1
. A null
or empty array returns -1
, but an array containing
""
returns the specified start index if the string is not
null
.
Examples:
indexOfAny(null, *, *, *) returns -1
indexOfAny(*, null, *, *) returns -1
indexOfAny(*, [null], *, *) returns -1
indexOfAny(*, [], *, *) returns -1
indexOfAny("zzabyycdxx", ["ab","cd"], 3, 7) returns 6
indexOfAny("zzabyycdxx", ["cd","ab"], 2, 7) returns 2
indexOfAny("zzabyycdxx", ["mn","op"], *, *) returns -1
indexOfAny("zzabyycdxx", ["mn",""], 3, *) returns 3
s
- the string to search (optionally null
)texts
- the strings to search for (optionally null
)fromIndex
- the start index within the stringtoIndex
- the end index within the string""
, or -1
if none of the
strings occurpublic static String insert(String s, String insert, int offset)
s
- the original stringinsert
- the string to be inserted into the original stringoffset
- the index of the original string where the insertion
should take placenull
if
the original string is null
public static boolean isLowerCase(String s)
true
if all the characters in string s
are lower case, ignoring any non-alphabetic characters.s
- the string in which to searchtrue
if all the characters in string s
are lower case, ignoring any non-alphabetic characters;
false
otherwisepublic static boolean isUpperCase(String s)
true
if all the characters in string s
are upper case, ignoring any non-alphabetic characters.s
- the string in which to searchtrue
if all the characters in string s
are upper case, ignoring any non-alphabetic characters;
false
otherwisepublic static int lastIndexOfAny(String s, char[] chars)
A null
string returns -1
. A null
or empty array returns -1
.
Examples:
lastIndexOfAny(null, *) returns -1
lastIndexOfAny(*, null) returns -1
lastIndexOfAny(*, []) returns -1
lastIndexOfAny("zzabyycdxx", ['a','c']) returns 6
lastIndexOfAny("zzabyycdxx", ['c','a']) returns 6
lastIndexOfAny("zzabyycdxx", ['m','n']) returns -1
s
- the string to search (optionally null
)chars
- the characters to search for (optionally null
)-1
if none of the
characters occurpublic static int lastIndexOfAny(String s, char[] chars, int toIndex)
A null
string returns -1
. A null
or empty array returns -1
.
Examples:
lastIndexOfAny(null, *, *) returns -1
lastIndexOfAny(*, null, *) returns -1
lastIndexOfAny(*, [], *) returns -1
lastIndexOfAny("zzabyycdxx", ['a','c'], 5) returns 2
lastIndexOfAny("zzabyycdxx", ['m','n'], *) returns -1
s
- the string to search (optionally null
)chars
- the characters to search for (optionally null
)toIndex
- the end index within the string-1
if none of the
characters occurpublic static int lastIndexOfAny(String s, char[] chars, int fromIndex, int toIndex)
A null
string returns -1
. A null
or empty array returns -1
.
Examples:
lastIndexOfAny(null, *, *, *) returns -1
lastIndexOfAny(*, null, *, *) returns -1
lastIndexOfAny(*, [], *, *) returns -1
lastIndexOfAny("zzabyycdxx", ['a','c'], 5, 7) returns 6
lastIndexOfAny("zzabyycdxx", ['m','n'], *, *) returns -1
s
- the string to search (optionally null
)chars
- the characters to search for (optionally null
)fromIndex
- the start index within the stringtoIndex
- the end index within the string-1
if none of the
characters occurpublic static int lastIndexOfAny(String s, String[] texts)
A null
string returns -1
. A null
or empty array returns -1
, but an array containing
""
returns 0
if the string is not
null
.
Examples:
lastIndexOfAny(null, *) returns -1
lastIndexOfAny(*, null) returns -1
lastIndexOfAny(*, []) returns -1
lastIndexOfAny(*, [null]) returns -1
lastIndexOfAny("zzabyycdxx", ["ab","cd"]) returns 6
lastIndexOfAny("zzabyycdxx", ["cd","ab"]) returns 6
lastIndexOfAny("zzabyycdxx", ["mn","op"]) returns -1
lastIndexOfAny("zzabyycdxx", ["mn",""]) returns 10
s
- the string to search (optionally null
)texts
- the strings to search for (optionally null
)0
if the search array contains
""
, or -1
if none of the strings occurpublic static int lastIndexOfAny(String s, String[] texts, int toIndex)
A null
string returns -1
. A null
or empty array returns -1
, but an array containing
""
returns the specified start index if the string is not
null
.
Examples:
lastIndexOfAny(null, *, *) returns -1
lastIndexOfAny(*, null, *) returns -1
lastIndexOfAny(*, [], *) returns -1
lastIndexOfAny(*, [null], *) returns -1
lastIndexOfAny("zzabyycdxx", ["ab","cd"], 5) returns 2
lastIndexOfAny("zzabyycdxx", ["cd","ab"], 5) returns 2
lastIndexOfAny("zzabyycdxx", ["mn","op"], *) returns -1
lastIndexOfAny("zzabyycdxx", ["mn",""], 5) returns 5
s
- the string to search (optionally null
)texts
- the strings to search for (optionally null
)toIndex
- the end index within the string""
, or -1
if none of the strings occurpublic static int lastIndexOfAny(String s, String[] texts, int fromIndex, int toIndex)
A null
string returns -1
. A null
or empty array returns -1
, but an array containing
""
returns the specified end index if the string is not
null
.
Examples:
lastIndexOfAny(null, *, *, *) returns -1
lastIndexOfAny(*, null, *, *) returns -1
lastIndexOfAny(*, [], *, *) returns -1
lastIndexOfAny(*, [null], *, *) returns -1
lastIndexOfAny("zzabyycdxx", ["ab","cd"], 2, 5) returns 2
lastIndexOfAny("zzabyycdxx", ["mn","op"], *, *) returns -1
lastIndexOfAny("zzabyycdxx", ["mn",""], 2, 5) returns 5
s
- the string to search (optionally null
)texts
- the strings to search for (optionally null
)fromIndex
- the start index within the stringtoIndex
- the end index within the string""
, or -1
if none of the
strings occurpublic static String lowerCase(String s)
s
- the string to convertnull
if the
string is null
String.toLowerCase()
public static void lowerCase(String... array)
array
- the array or sequence of string argumentspublic static String lowerCaseFirstLetter(String s)
s
- the string whose first character is to be convertedpublic static boolean matches(String s, String pattern)
true
if the specified pattern occurs at any position
in the string.s
- the stringpattern
- the pattern to search for in the stringtrue
if the specified pattern occurs at any position
in the stringpublic static boolean matchesIgnoreCase(String s, String pattern)
true
if the specified pattern occurs at any position
in the string, ignoring case.s
- the stringpattern
- the pattern to search for in the stringtrue
if the specified pattern occurs at any position
in the stringpublic static String merge(boolean[] array)
array
- the boolean values to mergenull
if the array is null
public static String merge(boolean[] array, String delimiter)
array
- the boolean values to mergedelimiter
- the delimiternull
if the array is null
public static String merge(char[] array)
array
- the characters to mergenull
if the array is null
public static String merge(char[] array, String delimiter)
array
- the characters to mergedelimiter
- the delimiternull
if the array is null
public static String merge(Collection<?> col)
col
- the collection of objectsnull
if the
collection is null
public static String merge(Collection<?> col, String delimiter)
col
- the collection of objectsdelimiter
- the string whose last index in the string marks where
to begin the substringnull
if the
collection is null
public static String merge(double[] array)
array
- the doubles to mergenull
if the array is
null
public static String merge(double[] array, String delimiter)
array
- the doubles to mergedelimiter
- the delimiternull
if the array is null
public static String merge(float[] array)
array
- the floats to mergenull
if the array is null
public static String merge(float[] array, String delimiter)
array
- the floats to mergedelimiter
- the delimiternull
if the array is null
public static String merge(int[] array)
array
- the integers to mergenull
if the array is null
public static String merge(int[] array, String delimiter)
array
- the integers to mergedelimiter
- the delimiternull
if the array is null
public static String merge(long[] array)
array
- the long integers to mergenull
if the array is null
public static String merge(long[] array, String delimiter)
array
- the long integers to mergedelimiter
- the delimiternull
if the array is null
public static String merge(Object[] array)
array
- the objects to mergenull
if the
array is null
public static String merge(Object[] array, String delimiter)
array
- the objects to mergedelimiter
- the delimiternull
if the array
is null
public static String merge(short[] array)
array
- the short integers to mergenull
if the array is null
public static String merge(short[] array, String delimiter)
array
- the short integers to mergedelimiter
- the delimiternull
if the array is null
public static String quote(String s)
Example:
quote("Hello, World!") returns "'Hello, World!'"
s
- the string to enclose in apostrophesnull
if the
string is null
public static String quote(String s, char quote)
Example:
quote("PATH", '%') returns "%PATH%"
s
- the string to enclose in quotesquote
- the character to insert to insert to the beginning of and
append to the end of the stringnull
if the string is null
public static String quote(String s, String quote)
Example:
quote("WARNING", "!!!") returns "!!!WARNING!!!"
s
- the string to enclose in quotesquote
- the quote string to insert to insert to the beginning of
and append to the end of the stringnull
if
the string is null
public static String randomId()
@Deprecated public static String randomize(String s)
RandomUtil.shuffle(String)
s
- the string whose characters are to be randomizedpublic static String randomString()
public static String randomString(int length)
length
- the character length of the randomized stringpublic static String read(Class<?> clazz, String name)
public static String read(ClassLoader classLoader, String name) throws IOException
IOException
public static String read(ClassLoader classLoader, String name, boolean all) throws IOException
IOException
public static String read(InputStream is) throws IOException
IOException
public static void readLines(InputStream is, Collection<String> lines) throws IOException
IOException
@Deprecated public static String remove(String s, String element)
removeFromList(String, String)
@Deprecated public static String remove(String s, String element, String delimiter)
removeFromList(String, String, String)
public static String removeChar(String s, char oldSub)
public static String removeChars(String s, char... oldSubs)
public static String removeFromList(String s, String element)
remove
string from string s
that
represents a list of comma delimited strings.
The resulting string ends with a comma even if the original string does not.
Examples:
remove("red,blue,green,yellow", "blue") returns "red,green,yellow,"
remove("blue", "blue") returns ""
remove("blue,", "blue") returns ""
s
- the string representing the list of comma delimited stringselement
- the string to removeremove
string removed, or null
if
the original string, the string to remove, or the delimiter is
null
public static String removeFromList(String s, String element, String delimiter)
remove
string from string s
that
represents a list of delimited strings.
The resulting string ends with the delimiter even if the original string does not.
Examples:
remove("red;blue;green;yellow", "blue", ";") returns "red;green;yellow;"
remove("blue", "blue", ";") returns ""
remove("blue;", "blue", ";") returns ""
s
- the string representing the list of delimited stringselement
- the string to removedelimiter
- the delimiterremove
string removed, or null
if the
original string, the string to remove, or the delimiter is
null
public static String removeSubstring(String s, String oldSub)
public static String removeSubstrings(String s, String... oldSubs)
public static String replace(String s, char oldSub, char newSub)
s
- the original stringoldSub
- the character to be searched for and replaced in the
original stringnewSub
- the character with which to replace the
oldSub
characteroldSub
character replaced with the
newSub
character, or null
if the
original string is null
public static String replace(String s, char oldSub, String newSub)
s
- the original stringoldSub
- the character to be searched for and replaced in the
original stringnewSub
- the string with which to replace the oldSub
characteroldSub
character replaced with the string
newSub
, or null
if the original string
is null
public static String replace(String s, char[] oldSubs, char[] newSubs)
public static String replace(String s, char[] oldSubs, String[] newSubs)
public static String replace(String s, String oldSub, String newSub)
s
- the original stringoldSub
- the string to be searched for and replaced in the original
stringnewSub
- the string with which to replace the oldSub
stringoldSub
string replaced with the string
newSub
, or null
if the original string
is null
public static String replace(String s, String oldSub, String newSub, int fromIndex)
s
- the original stringoldSub
- the string to be searched for and replaced in the original
stringnewSub
- the string with which to replace the oldSub
stringfromIndex
- the index of the original string from which to begin
searchingoldSub
string occurring after the specified
index replaced with the string newSub
, or
null
if the original string is null
public static String replace(String s, String begin, String end, Map<String,String> values)
For example, with the following initialized variables:
String s = "http://www.example-url/${userId}";
String begin = "${";
String end = "}";
Map values = new HashMap<String, String>();
values.put("userId", "jbloggs");
replace(s, begin, end, values)
returns
"http://www.example-url/jbloggs"
s
- the original stringbegin
- the string preceding the substring to be modified. This
string is excluded from the result.end
- the string following the substring to be modified. This
string is excluded from the result.values
- the key-value map valuesnull
is returned if the original string, the
beginning string, the ending string, or the key-map values are
null
.public static String replace(String s, String[] oldSubs, String[] newSubs)
s
- the original stringoldSubs
- the strings to be searched for and replaced in the
original stringnewSubs
- the strings with which to replace the
oldSubs
stringsoldSubs
strings replaced with the corresponding
newSubs
strings, or null
if the
original string, the oldSubs
array, or the
newSubs
is null
public static String replace(String s, String[] oldSubs, String[] newSubs, boolean exactMatch)
Examples:
replace("redorangeyellow", {"red", "orange", "yellow"}, {"RED","ORANGE", "YELLOW"}, false) returns "REDORANGEYELLOW"
replace("redorangeyellow", {"red", "orange", "yellow"}, {"RED","ORANGE", "YELLOW"}, true) returns "redorangeyellow"
replace("redorange yellow", {"red", "orange", "yellow"}, {"RED","ORANGE", "YELLOW"}, false) returns "REDORANGE YELLOW"
replace("redorange yellow", {"red", "orange", "yellow"}, {"RED","ORANGE", "YELLOW"}, true) returns "redorange YELLOW"
replace("red orange yellow", {"red", "orange", "yellow"}, {"RED","ORANGE", "YELLOW"}, false) returns "RED ORANGE YELLOW"
replace("redorange.yellow", {"red", "orange", "yellow"}, {"RED","ORANGE", * "YELLOW"}, true) returns "redorange.YELLOW"
s
- the original stringoldSubs
- the strings to be searched for and replaced in the
original stringnewSubs
- the strings with which to replace the
oldSubs
stringsexactMatch
- whether or not to replace only substrings of
s
that are surrounded by word boundariesexactMatch
is true
, a string
representing the original string with all occurrences of the
oldSubs
strings that are surrounded by word
boundaries replaced with the corresponding newSubs
strings, or else a string representing the original string with
all occurrences of the oldSubs
strings replaced with
the corresponding newSubs
strings, or
null
if the original string, the
oldSubs
array, or the newSubs
is
null
public static String replaceFirst(String s, char oldSub, char newSub)
s
- the original stringoldSub
- the character whose first occurrence in the original
string is to be searched for and replacednewSub
- the character with which to replace the first occurrence
of the oldSub
characteroldSub
replaced with the
character newSub
public static String replaceFirst(String s, char oldSub, String newSub)
s
- the original stringoldSub
- the character whose first occurrence in the original
string is to be searched for and replacednewSub
- the string with which to replace the first occurrence of
the oldSub
characteroldSub
replaced with the
string newSub
public static String replaceFirst(String s, String oldSub, String newSub)
s
- the original stringoldSub
- the string whose first occurrence in the original string
is to be searched for and replacednewSub
- the string with which to replace the first occurrence of
the oldSub
stringoldSub
replaced with the
string newSub
public static String replaceFirst(String s, String oldSub, String newSub, int fromIndex)
s
- the original stringoldSub
- the strings whose first occurrences are to be searched for
and replaced in the original stringnewSub
- the strings with which to replace the first occurrences of
the oldSubs
stringsfromIndex
- the start index within the stringoldSubs
strings replaced with the
corresponding newSubs
strings, or null
if the original string, the oldSubs
string, or the
newSubs
string is null
public static String replaceFirst(String s, String[] oldSubs, String[] newSubs)
s
- the original stringoldSubs
- the strings whose first occurrences are to be searched
for and replaced in the original stringnewSubs
- the strings with which to replace the first occurrences
of the oldSubs
stringsoldSubs
strings replaced with the
corresponding newSubs
strings, or null
if the original string, the oldSubs
array, or the
newSubs
is null
public static String replaceLast(String s, char oldSub, char newSub)
s
- the original stringoldSub
- the character whose last occurrence in the original string
is to be searched for and replacednewSub
- the character with which to replace the last occurrence of
the oldSub
characteroldSub
replaced with the
character newSub
public static String replaceLast(String s, char oldSub, String newSub)
s
- the original stringoldSub
- the character whose last occurrence in the original string
is to be searched for and replacednewSub
- the string with which to replace the last occurrence of
the oldSub
characteroldSub
replaced with the
string newSub
public static String replaceLast(String s, String oldSub, String newSub)
oldSub
in the
string s
with the string newSub
.s
- the original stringoldSub
- the string whose last occurrence in the original string is
to be searched for and replacednewSub
- the string with which to replace the last occurrence of
the oldSub
stringoldSub
replaced with the
string newSub
public static String replaceLast(String s, String[] oldSubs, String[] newSubs)
s
- the original stringoldSubs
- the strings whose last occurrences are to be searched for
and replaced in the original stringnewSubs
- the strings with which to replace the last occurrences of
the oldSubs
stringsoldSubs
strings replaced with the
corresponding newSubs
strings, or null
if the original string, the oldSubs
array, or the
newSubs
is null
public static StringBundler replaceToStringBundler(String s, String begin, String end, Map<String,String> values)
StringBundler
.
For example, with the following initialized variables:
String s = "http://www.example-url/${userId}";
String begin = "${";
String end = "}";
Map values = new HashMap<String, String>();
values.put("userId", "jbloggs");
StringBundler sb = replaceToStringBundler(s, begin, end,
values)
sb.toString()
returns
"http://www.example-url/jbloggs"
s
- the original stringbegin
- the string preceding the substring to be modified. This
string is excluded from the result.end
- the string following the substring to be modified. This
string is excluded from the result.values
- the key-value map valuesnull
is returned if the original
string, the beginning string, the ending string, or the key-map
values are null
.replace(String, String, String, Map)
public static StringBundler replaceWithStringBundler(String s, String begin, String end, Map<String,StringBundler> values)
StringBundler
.s
- the original stringbegin
- the string preceding the substring to be modified. This
string is removed from the result.end
- the string following the substring to be modified. This
string is removed from the result.values
- the key-value map values, which has string keys and StringBundler
valuesnull
is returned if the original
string, the beginning string, the ending string, or the key-map
values are null
.@Deprecated public static String reverse(String s)
s
- the original string@Deprecated public static String safePath(String path)
Example:
safePath("http://www.liferay.com") returns "http:/www.liferay.com"
path
- the original stringpublic static String shorten(String s)
The suffix is only added if the original string exceeds 20 characters. If the original string exceeds 20 characters and it contains whitespace, the string is shortened at the first whitespace character.
Examples:
shorten("12345678901234567890xyz") returns "12345678901234567..."
shorten("1 345678901234567890xyz") returns "1..."
shorten(" 2345678901234567890xyz") returns "..."
shorten("12345678901234567890") returns "12345678901234567890"
shorten(" 2345678901234567890") returns " 2345678901234567890"
s
- the original stringpublic static String shorten(String s, int length)
The suffix is only added if the original string exceeds the specified length. If the original string exceeds the specified length and it contains whitespace, the string is shortened at the first whitespace character.
Examples:
shorten("123456789", 8) returns "12345..."
shorten("1 3456789", 8) returns "1..."
shorten(" 23456789", 8) returns "..."
shorten("12345678", 8) returns "12345678"
shorten(" 1234567", 8) returns " 1234567"
s
- the original stringlength
- the number of characters to limit from the original stringpublic static String shorten(String s, int length, String suffix)
The suffix is only added if the original string exceeds the specified length. If the original string exceeds the specified length and it contains whitespace, the string is shortened at the first whitespace character.
Examples:
shorten("12345678901234", 13, "... etc.") returns "12345... etc."
shorten("1 345678901234", 13, "... etc.") returns "1... etc."
shorten(" 2345678901234", 13, "... etc.") returns "... etc."
shorten("1234567890123", 13, "... etc.") returns "1234567890123"
shorten(" 123456789012", 13, "... etc.") returns " 123456789012"
s
- the original stringlength
- the number of characters to limit from the original stringsuffix
- the suffix to appendpublic static String shorten(String s, String suffix)
The suffix is only added if the original string exceeds 20 characters. If the original string exceeds 20 characters and it contains whitespace, the string is shortened at the first whitespace character.
Examples:
shorten("12345678901234567890xyz", "... etc.") returns "123456789012... etc."
shorten("1 345678901234567890xyz", "... etc.") returns "1... etc."
shorten(" 2345678901234567890xyz", "... etc.") returns "... etc."
shorten("12345678901234567890", "... etc.") returns "12345678901234567890"
shorten(" 2345678901234567890", "... etc.") returns " 2345678901234567890"
s
- the original stringsuffix
- the suffix to appendpublic static String[] split(String s)
s
around comma characters.
Examples:
split("Alice,Bob,Charlie") returns {"Alice", "Bob", "Charlie"}
split("Alice, Bob, Charlie") returns {"Alice", " Bob", " Charlie"}
s
- the string to splits
around comma characters, or an empty string array
if s
is null
or s
is emptypublic static boolean[] split(String s, boolean x)
s
around comma characters returning the
boolean values of the substrings.s
- the string to splitx
- the default value to use for a substring in case an exception
occurs in getting the boolean value for that substrings
around comma characters, or an empty array if
s
is null
public static String[] split(String s, char delimiter)
s
around the specified delimiter.
Example:
splitLines("First;Second;Third", ';') returns {"First","Second","Third"}
s
- the string to splitdelimiter
- the delimiters
around the specified delimiter character, or an
empty string array if s
is null
or if
s
is emptypublic static double[] split(String s, double x)
s
around comma characters returning the
double-precision decimal values of the substrings.s
- the string to splitx
- the default value to use for a substring in case an exception
occurs in getting the double-precision decimal value for that
substrings
around comma characters, or an
empty array if s
is null
public static float[] split(String s, float x)
s
around comma characters returning the
decimal values of the substrings.s
- the string to splitx
- the default value to use for a substring in case an exception
occurs in getting the decimal value for that substrings
around comma characters, or an empty array if
s
is null
public static int[] split(String s, int x)
s
around comma characters returning the
integer values of the substrings.s
- the string to splitx
- the default value to use for a substring in case an exception
occurs in getting the integer value for that substrings
around comma characters, or an empty array if
s
is null
public static long[] split(String s, long x)
s
around comma characters returning the
long integer values of the substrings.s
- the string to splitx
- the default value to use for a substring in case an exception
occurs in getting the long integer value for that substrings
around comma characters, or an empty array if
s
is null
public static short[] split(String s, short x)
s
around comma characters returning the
short integer values of the substrings.s
- the string to splitx
- the default value to use for a substring in case an exception
occurs in getting the short integer value for that substrings
around comma characters, or an empty array if
s
is null
public static String[] split(String s, String delimiter)
s
around the specified delimiter string.
Example:
splitLines("oneandtwoandthreeandfour", "and") returns {"one","two","three","four"}
s
- the string to splitdelimiter
- the delimiters
around the specified delimiter string, or an empty
string array if s
is null
or equals the
delimiterpublic static boolean[] split(String s, String delimiter, boolean x)
s
around the specified delimiter returning
the boolean values of the substrings.s
- the string to splitdelimiter
- the delimiterx
- the default value to use for a substring in case an exception
occurs in getting the boolean value for that substrings
around the specified delimiter string, or an empty
array if s
is null
public static double[] split(String s, String delimiter, double x)
s
around the specified delimiter returning
the double-precision decimal values of the substrings.s
- the string to splitdelimiter
- the delimiterx
- the default value to use for a substring in case an exception
occurs in getting the double-precision decimal value for that
substrings
around the specified delimiter
string, or an empty array if s
is null
public static float[] split(String s, String delimiter, float x)
s
around the specified delimiter returning
the decimal values of the substrings.s
- the string to splitdelimiter
- the delimiterx
- the default value to use for a substring in case an exception
occurs in getting the decimal value for that substrings
around the specified delimiter string, or an empty
array if s
is null
public static int[] split(String s, String delimiter, int x)
s
around the specified delimiter returning
the integer values of the substrings.s
- the string to splitdelimiter
- the delimiterx
- the default value to use for a substring in case an exception
occurs in getting the integer value for that substrings
around the specified delimiter string, or an empty
array if s
is null
public static long[] split(String s, String delimiter, long x)
s
around the specified delimiter returning
the long integer values of the substrings.s
- the string to splitdelimiter
- the delimiterx
- the default value to use for a substring in case an exception
occurs in getting the long integer value for that substrings
around the specified delimiter string, or an empty
array if s
is null
public static short[] split(String s, String delimiter, short x)
s
around the specified delimiter returning
the short integer values of the substrings.s
- the string to splitdelimiter
- the delimiterx
- the default value to use for a substring in case an exception
occurs in getting the short integer value for that substrings
around the specified delimiter string, or an empty
array if s
is null
public static String[] splitLines(String s)
s
around return and newline characters.
Example:
splitLines("Red\rBlue\nGreen") returns {"Red","Blue","Green"}
s
- the string to splits
around return and newline characters, or an empty
string array if string s
is null
public static boolean startsWith(String s, char begin)
true
if, ignoring case, the string starts with the
specified character.s
- the stringbegin
- the character against which the initial character of the
string is to be comparedtrue
if, ignoring case, the string starts with the
specified character; false
otherwisepublic static boolean startsWith(String s, String start)
true
if, ignoring case, the string starts with the
specified start string.s
- the original stringstart
- the string against which the beginning of string
s
are to be comparedtrue
if, ignoring case, the string starts with the
specified start string; false
otherwisepublic static int startsWithWeight(String s1, String s2)
s1
and
s2
have in common before their characters deviate.s1
- string 1s2
- string 2s1
and
s2
have in common before their characters deviate@Deprecated public static String strip(String s, char remove)
removeChar(String,
char)
s
with all
occurrences of the specified character removed.
Example:
strip("Mississipi", 'i') returns "Mssssp"
s
- the string from which to strip all occurrences of the
characterremove
- the character to strip from the strings
with all
occurrences of the specified character removed, or
null
if s
is null
@Deprecated public static String strip(String s, char[] remove)
removeChars(String,
char...)
s
with all
occurrences of the specified characters removed.
Example:
strip("Hello World", {' ', 'l', 'd'}) returns "HeoWor"
s
- the string from which to strip all occurrences the
charactersremove
- the characters to strip from the strings
with all
occurrences of the specified characters removed, or
null
if s
is null
public static String stripBetween(String s, String begin, String end)
s
up to but not including the string begin
concatenated with the substring of s
after but not including
the string end
.
Example:
stripBetween("One small step for man, one giant leap for mankind", "step", "giant ") returns "One small leap for mankind"
s
- the string from which to strip a substringbegin
- the beginning characters of the substring to be removedend
- the ending characters of the substring to be removeds
up to but not including the string
begin
concatenated with the substring of
s
after but not including the string
end
, or the original string if the value of
s
, begin
, or end
are
null
public static String stripCDATA(String s)
s
with its
<![CDATA[]]>
wrapper removed.
Example:
stripCDATA("<![CDATA[One small step for man]]>") returns "One small step for man"
s
- the string from which to strip its CDATA wrappers
with its
<![CDATA[]]>
wrapper removed, or
null
if s
is null
public static String stripParentheticalSuffix(String s)
s
without an
appended parenthetical suffix. If there is not a space directly before
the opening parenthesis, the parenthetical suffix is not stripped.
Examples:
stripParentheticalSuffix("file") returns "file"
stripParentheticalSuffix("file (0)") returns "file"
stripParentheticalSuffix("file (0 0)") returns "file"
stripParentheticalSuffix("file(0)") returns "file(0)"
s
- the string from which to strip its parenthetical suffixs
without an
appended parenthetical suffixpublic static String toCharCode(String s)
s
.
Examples:
toCharCode("a") returns "97"
toCharCode("b") returns "98"
toCharCode("c") returns "99"
toCharCode("What's for lunch?") returns "87104971163911532102111114321081171109910463"
s
- the string whose character codes are to be representeds
public static String toHexString(int i)
Examples:
toHexString(10) returns "a"
toHexString(15) returns "f"
toHexString(10995) returns "2af3"
i
- the integer to convertpublic static String toHexString(long l)
Example:
toHexString(12345678910L) returns "2dfdc1c3e"
l
- the long integer to convertpublic static String toHexString(Object obj)
Integer
or Long
object type. If the object is
not an instance of these types, the object's original value is returned.obj
- the object to convertpublic static String toLowerCase(String s)
s
- the string to convertnull
if the
string is null
public static String toLowerCase(String s, Locale locale)
s
- the string to convertlocale
- apply this locale's rulesnull
if the
string is null
GetterUtil#_toLowerCase
public static String toUpperCase(String s)
s
- the string to convertnull
if the
string is null
public static String toUpperCase(String s, Locale locale)
s
- the string to convertlocale
- apply this locale's rulesnull
if the
string is null
public static String trim(String s)
s
- the original stringpublic static String trim(String s, char c)
c
.
Examples:
trim(" \tHey\t ", '\t') returns "\tHey\t"
trim(" \t Hey \t ", '\t') returns "\t Hey \t"
s
- the original stringc
- the whitespace character to limit trimmingc
public static String trim(String s, char[] exceptions)
exceptions
.s
- the original stringexceptions
- the whitespace characters to limit trimmingexceptions
public static String trimLeading(String s)
s
- the original stringpublic static String trimLeading(String s, char c)
c
.s
- the original stringc
- the whitespace character to limit trimmingc
public static String trimLeading(String s, char[] exceptions)
exceptions
.s
- the original stringexceptions
- the whitespace characters to limit trimmingexceptions
public static String trimTrailing(String s)
s
- the original stringpublic static String trimTrailing(String s, char c)
c
.s
- the original stringc
- the whitespace character to limit trimmingc
public static String trimTrailing(String s, char[] exceptions)
exceptions
.s
- the original stringexceptions
- the whitespace characters to limit trimmingexceptions
public static String unquote(String s)
s
- the original stringnull
or
emptypublic static String upperCase(String s)
s
- the string to convertnull
if the
string is null
String.toUpperCase()
public static String upperCaseFirstLetter(String s)
s
- the string whose first character is to be converted@Deprecated public static String valueOf(Object obj)
obj
- the object whose string value is to be returnedString.valueOf(Object obj)
public static boolean wildcardMatches(String s, String wildcard, char singleWildcardCharacter, char multipleWildcardCharacter, char escapeWildcardCharacter, boolean caseSensitive)
true
if the string matches the wildcard pattern.
For example, with the following initialized variables:
String s = "*master";
String wildcard = "/*m?st*";
char singleWildcardCharacter = '?';
char multipleWildcardCharacter = '*';
char escapeWildcardCharacter = '/';
boolean caseSensitive = false;
wildcardMatches(s, wildcard, singleWildcardCharacter,
multipleWildcardCharacter, escapeWildcardCharacter, caseSensitive)
returns true
s
- the string to be checkedwildcard
- the wildcard pattern to matchsingleWildcardCharacter
- the char used to match exactly one
charactermultipleWildcardCharacter
- the char used to match 0
or more charactersescapeWildcardCharacter
- the char placed in front of a wildcard
character to indicate that it should be interpreted as a regular
charactercaseSensitive
- whether to use case sensitivitytrue
if the string matches the wildcard pattern;
false
otherwise@Deprecated public static String wrap(String text)
80
column width limit,
using a StringPool.NEW_LINE
to break each wrapped line.text
- the text to wrapnull
if the text is null
@Deprecated public static String wrap(String text, int width, String lineSeparator)
text
- the text to wrapwidth
- the column width limit for the textlineSeparator
- the string to use in breaking each wrapped linenull
if the text is
null