public class StringUtil extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
StringUtil.AlphanumComparator
This is an updated version of Alphanum Algorithm Comparator
with enhancements made by Daniel Migowski, Andre Bogus, and David Koelle
|
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static boolean |
containHtmlCR(java.lang.String text)
Return true if the specified text contains HTML line break sequence.
|
static boolean |
equals(java.lang.String s1,
java.lang.String s2)
Return true if the specified String are exactly the same
|
static boolean |
equals(java.lang.String s1,
java.lang.String s2,
boolean trim)
Return true if the specified String are exactly the same.
|
static java.lang.String |
getFlattened(java.lang.String string)
Creates a flattened version of the provided String.
|
static int |
getNextCtrlCharIndex(java.lang.CharSequence value,
int startIndex)
Return the index of next control char from specified
startIndex in specified
string. |
static int |
getNextDigitCharIndex(java.lang.CharSequence value,
int from)
Return the index of next digit char from specified index in specified string
return -1 if not found |
static int |
getNextLetterCharIndex(java.lang.CharSequence value,
int from)
Return the index of next letter char from specified index in specified string
return -1 if not found |
static int |
getNextNonDigitCharIndex(java.lang.CharSequence value,
int from)
Return the index of next non digit char from specified index in specified string
return -1 if not found |
static int |
getNextNonLetterCharIndex(java.lang.CharSequence value,
int from)
Return the index of next non letter char from specified index in specified string
return -1 if not found |
static java.lang.CharSequence |
getNextNumber(java.lang.CharSequence text,
int index)
Returns the next number found from specified
startIndex in specified string. |
static int |
getPreviousDigitCharIndex(java.lang.CharSequence value,
int from)
Return the index of previous digit char from specified index in specified string
return -1 if not found |
static int |
getPreviousLetterCharIndex(java.lang.CharSequence value,
int from)
Return the index of previous letter char from specified index in specified string
return -1 if not found |
static int |
getPreviousNonDigitCharIndex(java.lang.CharSequence value,
int from)
Return the index of previous non digit char from specified index in specified string
return -1 if not found |
static int |
getPreviousNonLetterCharIndex(java.lang.CharSequence value,
int from)
Return the index of previous non letter char from specified index in specified string
Return -1 if not found. |
static java.lang.String |
getValue(java.lang.String value,
java.lang.String defaultValue)
Return defaultValue if value is empty
|
static java.lang.String |
htmlBoldSubstring(java.lang.String text,
java.lang.String keyword,
boolean ignoreCase)
Bold (inserting HTML bold tag) the specified keyword in the text.
|
static boolean |
isEmpty(java.lang.String value)
Return true if the specified String is empty.
|
static boolean |
isEmpty(java.lang.String value,
boolean trim)
Return true if the specified String is empty.
|
static java.lang.String |
limit(java.lang.String value,
int maxlen)
Limit the length of the specified string to maxlen.
|
static java.lang.String |
limit(java.lang.String value,
int maxlen,
boolean tailLimit)
Limit the length of the specified string to maxlen.
|
static boolean |
parseBoolean(java.lang.String s,
boolean def)
Try to parse a boolean from the specified String and return it.
|
static byte[] |
parseBytes(java.lang.String s,
byte[] def)
Try to parse a array of byte from the specified String and return it.
|
static double |
parseDouble(java.lang.String s,
double def)
Try to parse a double from the specified String and return it.
|
static float |
parseFloat(java.lang.String s,
float def)
Try to parse a float from the specified String and return it.
|
static int |
parseInt(java.lang.String s,
int def)
Try to parse a integer from the specified String and return it.
|
static long |
parseLong(java.lang.String s,
long def)
Try to parse a long integer from the specified String and return it.
|
static java.lang.String |
removeCR(java.lang.String text)
Remove all C line break sequence :
"\n", "\r", "\r\n" from the specified text. |
static java.lang.String |
removeLast(java.lang.String value,
int count)
Remove
count characters from the end of specified string. |
static java.lang.String |
replaceCR(java.lang.String text,
java.lang.String str)
Replace all C line break sequence :
"\n", "\r", "\r\n" from the specified text by str . |
static java.util.List<java.lang.String> |
split(java.lang.String text)
Split a text into word based on space character while preserving quoted sentences.
|
static java.lang.String |
toHexaString(int value)
Returns a string representation of the integer argument as an
unsigned integer in base 16.
|
static java.lang.String |
toHexaString(int value,
int size)
Returns a string representation of the integer argument as an
unsigned integer in base 16.
|
static java.lang.String |
toHtmlCR(java.lang.String text)
Convert the C line break sequence :
"\n", "\r", "\r\n" to HTML line break sequence. |
static java.lang.String |
toString(boolean value)
Returns a String object representing the specified
boolean.
|
static java.lang.String |
toString(byte[] value)
Return a string representation of the byte array argument.
|
static java.lang.String |
toString(double value)
Returns a string representation of the
double argument. |
static java.lang.String |
toString(double value,
int numDecimal)
Returns a string representation of the
double argument
with specified number of decimal. |
static java.lang.String |
toString(float value)
Returns a string representation of the
float argument. |
static java.lang.String |
toString(int value)
Returns a
String object representing the specified integer. |
static java.lang.String |
toString(int value,
int minSize)
Returns a
String object representing the specified integer. |
static java.lang.String |
toString(long value)
Returns a
String object representing the specified long . |
static java.lang.String |
toStringEx(double value,
int size)
Returns a string representation of the
double argument with specified size :toString(1.23456, 5) --> "1.2345" toString(123.4567, 4) --> "123.4" toString(1234.567, 2) --> "1234" as we never trunk integer part. |
static java.lang.String |
trunc(java.lang.String fullText,
java.lang.String keyword,
int maxSize)
Truncate the text to a specific size, according a keyword.
|
static java.lang.String |
wildcardToRegex(java.lang.String wildcard)
Converts wildcard to regular expression.
|
public StringUtil()
public static java.lang.String getValue(java.lang.String value, java.lang.String defaultValue)
public static java.lang.CharSequence getNextNumber(java.lang.CharSequence text, int index)
startIndex
in specified string.public static int getPreviousDigitCharIndex(java.lang.CharSequence value, int from)
public static int getPreviousLetterCharIndex(java.lang.CharSequence value, int from)
public static int getPreviousNonDigitCharIndex(java.lang.CharSequence value, int from)
public static int getPreviousNonLetterCharIndex(java.lang.CharSequence value, int from)
public static int getNextDigitCharIndex(java.lang.CharSequence value, int from)
public static int getNextLetterCharIndex(java.lang.CharSequence value, int from)
public static int getNextNonDigitCharIndex(java.lang.CharSequence value, int from)
public static int getNextNonLetterCharIndex(java.lang.CharSequence value, int from)
public static int getNextCtrlCharIndex(java.lang.CharSequence value, int startIndex)
startIndex
in specified
string.public static java.lang.String limit(java.lang.String value, int maxlen, boolean tailLimit)
public static java.lang.String limit(java.lang.String value, int maxlen)
public static java.lang.String trunc(java.lang.String fullText, java.lang.String keyword, int maxSize)
fullText
- : text to be truncated.keyword
- : string to be found in the text and truncated around.maxSize
- : max size of the stringpublic static boolean equals(java.lang.String s1, java.lang.String s2, boolean trim)
trim
- if true then string are trimmed before comparisonpublic static boolean equals(java.lang.String s1, java.lang.String s2)
public static boolean isEmpty(java.lang.String value, boolean trim)
trim
- trim the String before doing the empty testpublic static boolean isEmpty(java.lang.String value)
public static boolean parseBoolean(java.lang.String s, boolean def)
public static int parseInt(java.lang.String s, int def)
public static long parseLong(java.lang.String s, long def)
public static float parseFloat(java.lang.String s, float def)
public static double parseDouble(java.lang.String s, double def)
public static byte[] parseBytes(java.lang.String s, byte[] def)
public static java.lang.String toString(boolean value)
true
, then
the string "true"
will be returned, otherwise the
string "false"
will be returned.public static java.lang.String toString(int value)
String
object representing the specified integer.public static java.lang.String toString(int value, int minSize)
String
object representing the specified integer.public static java.lang.String toString(long value)
String
object representing the specified long
.public static java.lang.String toString(float value)
float
argument.public static java.lang.String toString(double value)
double
argument.public static java.lang.String toString(double value, int numDecimal)
double
argument
with specified number of decimal.public static java.lang.String toStringEx(double value, int size)
double
argument with specified size :toString(1.23456, 5)
--> "1.2345"
toString(123.4567, 4)
--> "123.4"
toString(1234.567, 2)
--> "1234"
as we never trunk integer part.toString(1234.5, 10)
--> "1234.5"
as we never trunk integer part.public static java.lang.String toString(byte[] value)
public static java.lang.String toHexaString(int value)
public static java.lang.String toHexaString(int value, int size)
public static java.lang.String removeLast(java.lang.String value, int count)
count
characters from the end of specified string.public static java.lang.String getFlattened(java.lang.String string)
string
- the string to flattenpublic static java.lang.String replaceCR(java.lang.String text, java.lang.String str)
"\n", "\r", "\r\n"
text
by str
.public static java.lang.String removeCR(java.lang.String text)
"\n", "\r", "\r\n"
public static java.lang.String toHtmlCR(java.lang.String text)
"\n", "\r", "\r\n"
public static boolean containHtmlCR(java.lang.String text)
public static java.lang.String htmlBoldSubstring(java.lang.String text, java.lang.String keyword, boolean ignoreCase)
public static java.util.List<java.lang.String> split(java.lang.String text)
text
- text to split into word.public static java.lang.String wildcardToRegex(java.lang.String wildcard)
wildcard
-