|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.github.drinkjava2.jdialects.StrUtils
public class StrUtils
String Utilities usually used inside of framework
| Field Summary | |
|---|---|
static String |
WHITESPACE
|
| Method Summary | |
|---|---|
static boolean |
arraysEqual(Object[] array1,
Object[] array2)
Compare 2 array |
static String |
arrayToString(Object[] array)
Change a Object array to "obj1,obj2...,objn" String |
static String |
arrayToString(Object[] array,
String seperateString)
Change a Object array to connected string by given seperateString |
static String |
arrayToStringButSkipFirst(Object[] array)
Change a Object array to "obj1,obj2...,objn" String |
static boolean |
containsIgnoreCase(String str,
String searchStr)
Find if exist searchStr in str ignore case |
static boolean |
containsWhitespace(CharSequence str)
Check whether the given CharSequence contains any whitespace characters. |
static boolean |
containsWhitespace(String str)
Check whether the given String contains any whitespace characters. |
static int |
countMatches(CharSequence str,
char ch)
Counts how many times the char appears in the given string. |
static String |
formatSQL(String sql)
Format all " ", \t, \r... |
static String |
getRandomString(int length)
|
static boolean |
hasLength(CharSequence str)
Check that the given CharSequence is neither null nor of length 0. |
static boolean |
hasLength(String str)
Check that the given String is neither null nor of length 0. |
static int |
indexOfIgnoreCase(String str,
String searchStr)
Return first postion ignore case, return -1 if not found |
static boolean |
isCapitalizedString(String str)
Return true if first letter is Capitalised |
static boolean |
isEmpty(Object str)
Check whether the given String is empty. |
static boolean |
isInvisibleChar(char c)
Return true if is an invisible Char like space, tab, return... |
static boolean |
isNormalLetters(char c)
Check if a String only have a-z,A-Z,0-9,"_" characters |
static String[] |
joinStringArray(String[] array1,
String[] array2)
Join 2 String array into one |
static int |
lastIndexOfIgnoreCase(String str,
String searchStr)
Return last sub-String position ignore case, return -1 if not found |
static String |
listToString(List<?> lst)
Change a Object List to "obj1,obj2...,objn" String |
static String |
replace(String originString,
String oldPattern,
String newPattern)
Replace all occurrences of a substring within a string with another string. |
static String |
replaceFirst(String originString,
String oldPattern,
String newPattern)
Replace first occurrences of a substring within a string with another string. |
static String |
replaceIgnoreCase(String text,
String findtxt,
String replacetxt)
Replace all sub strings ignore case replaceIgnoreCase("AbcDECd", "Cd", "FF") = "AbFFEFF" |
static String[] |
split(String str,
char separatorChar)
Splits the provided text into an array, separator specified. |
static String[] |
split(String separators,
String list)
|
static String[] |
split(String separators,
String list,
boolean include)
|
static boolean |
startsWithIgnoreCase(String str,
String prefix)
Test if the given String starts with the specified prefix, ignoring upper/lower case. |
static String |
substringAfter(String str,
String separator)
Gets the substring after the first occurrence of a separator. |
static String |
substringAfterLast(String str,
String separator)
Gets the substring after the last occurrence of a separator. |
static String |
substringBefore(String str,
String separator)
Gets the substring before the first occurrence of a separator. |
static String |
substringBeforeLast(String str,
String separator)
Gets the substring before the last occurrence of a separator. |
static String |
substringBetween(String str,
String open,
String close)
Gets the String that is nested in between two Strings. |
static String[] |
substringsBetween(String str,
String open,
String close)
Searches a String for substrings delimited by a start and end tag, returning all matching substrings in an array. |
static String |
toLowerCaseFirstOne(String s)
First letter change to lower |
static String |
toUpperCaseFirstOne(String s)
First letter change to capitalised |
static String |
trimAllWhitespace(String str)
Trim all whitespace from the given String: leading, trailing, and in between characters. |
static String |
trimLeadingCharacter(String str,
char leadingCharacter)
Trim all occurrences of the supplied leading character from the given String. |
static String |
trimLeadingWhitespace(String str)
Trim leading whitespace from the given String. |
static String |
trimTrailingCharacter(String str,
char trailingCharacter)
Trim all occurrences of the supplied trailing character from the given String. |
static String |
trimTrailingWhitespace(String str)
Trim trailing whitespace from the given String. |
static String |
trimWhitespace(String str)
Trim leading and trailing whitespace from the given String. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String WHITESPACE
| Method Detail |
|---|
public static boolean isEmpty(Object str)
public static boolean hasLength(CharSequence str)
null nor of length 0.
Note: Will return true for a CharSequence that purely consists of
whitespace.
StrUtils.hasLength(null) = false
StrUtils.hasLength("") = false
StrUtils.hasLength(" ") = true
StrUtils.hasLength("Hello") = true
str - the CharSequence to check (may be null)
true if the CharSequence is not null and has length#hasText(String)public static boolean hasLength(String str)
null nor of length 0. Note:
Will return true for a String that purely consists of whitespace.
str - the String to check (may be null)
true if the String is not null and has lengthhasLength(CharSequence)public static boolean containsWhitespace(CharSequence str)
str - the CharSequence to check (may be null)
true if the CharSequence is not empty and contains at least 1
whitespace characterCharacter.isWhitespace(char)public static boolean containsWhitespace(String str)
str - the String to check (may be null)
true if the String is not empty and contains at least 1
whitespace charactercontainsWhitespace(CharSequence)public static String trimWhitespace(String str)
str - the String to check
Character.isWhitespace(char)public static String trimAllWhitespace(String str)
str - the String to check
Character.isWhitespace(char)public static String trimLeadingWhitespace(String str)
str - the String to check
Character.isWhitespace(char)public static String trimTrailingWhitespace(String str)
str - the String to check
Character.isWhitespace(char)
public static String trimLeadingCharacter(String str,
char leadingCharacter)
str - the String to checkleadingCharacter - the leading character to be trimmed
public static String trimTrailingCharacter(String str,
char trailingCharacter)
str - the String to checktrailingCharacter - the trailing character to be trimmed
public static boolean startsWithIgnoreCase(String str,
String prefix)
str - the String to checkprefix - the prefix to look forString.startsWith(java.lang.String, int)
public static boolean containsIgnoreCase(String str,
String searchStr)
public static String replace(String originString,
String oldPattern,
String newPattern)
originString - The original StringoldPattern - old String Pattern to replacenewPattern - new String pattern to insert
public static String replaceFirst(String originString,
String oldPattern,
String newPattern)
originString - The original StringoldPattern - old String Pattern to replacenewPattern - new String pattern to insert
public static String replaceIgnoreCase(String text,
String findtxt,
String replacetxt)
public static int indexOfIgnoreCase(String str,
String searchStr)
public static int lastIndexOfIgnoreCase(String str,
String searchStr)
public 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. For more control over the split use the StrTokenizer class.
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 b c", ' ') = ["a", "b", "c"]
str - the String to parse, may be nullseparatorChar - the character used as the delimiter
null if null String input
public static String[] split(String separators,
String list)
public static String[] split(String separators,
String list,
boolean include)
public static String[] substringsBetween(String str,
String open,
String close)
Searches a String for substrings delimited by a start and end tag, returning all matching substrings in an array.
A null input String returns null. A null open/close
returns null (no match). An empty ("") open/close returns
null (no match).
StringUtils.substringsBetween("[a][b][c]", "[", "]") = ["a","b","c"]
StringUtils.substringsBetween(null, *, *) = null
StringUtils.substringsBetween(*, null, *) = null
StringUtils.substringsBetween(*, *, null) = null
StringUtils.substringsBetween("", "[", "]") = []
str - the String containing the substrings, null returns null, empty
returns emptyopen - the String identifying the start of the substring, empty returns
nullclose - the String identifying the end of the substring, empty returns
null
null if no match
public static String substringBetween(String str,
String open,
String close)
null input String returns null. A
null open/close returns null (no match). An empty
("") open and close returns an empty string.
StringUtils.substringBetween("wx[b]yz", "[", "]") = "b"
StringUtils.substringBetween(null, *, *) = null
StringUtils.substringBetween(*, null, *) = null
StringUtils.substringBetween(*, *, null) = null
StringUtils.substringBetween("", "", "") = ""
StringUtils.substringBetween("", "", "]") = null
StringUtils.substringBetween("", "[", "]") = null
StringUtils.substringBetween("yabcz", "", "") = ""
StringUtils.substringBetween("yabcz", "y", "z") = "abc"
StringUtils.substringBetween("yabczyabcz", "y", "z") = "abc"
str - the String containing the substring, may be nullopen - the String before the substring, may be nullclose - the String after the substring, may be null
null if no match
public static String substringBefore(String str,
String separator)
Gets the substring before the first occurrence of a separator. The separator is not returned.
A null string input will return null. An empty ("") string
input will return the empty string. A null separator will return the
input string.
If nothing is found, the string input is returned.
StringUtils.substringBefore(null, *) = null
StringUtils.substringBefore("", *) = ""
StringUtils.substringBefore("abc", "a") = ""
StringUtils.substringBefore("abcba", "b") = "a"
StringUtils.substringBefore("abc", "c") = "ab"
StringUtils.substringBefore("abc", "d") = "abc"
StringUtils.substringBefore("abc", "") = ""
StringUtils.substringBefore("abc", null) = "abc"
str - the String to get a substring from, may be nullseparator - the String to search for, may be null
null if null String input
public static String substringAfter(String str,
String separator)
Gets the substring after the first occurrence of a separator. The separator is not returned.
A null string input will return null. An empty ("") string
input will return the empty string. A null separator will return the
empty string if the input string is not null.
If nothing is found, the empty string is returned.
StringUtils.substringAfter(null, *) = null
StringUtils.substringAfter("", *) = ""
StringUtils.substringAfter(*, null) = ""
StringUtils.substringAfter("abc", "a") = "bc"
StringUtils.substringAfter("abcba", "b") = "cba"
StringUtils.substringAfter("abc", "c") = ""
StringUtils.substringAfter("abc", "d") = ""
StringUtils.substringAfter("abc", "") = "abc"
str - the String to get a substring from, may be nullseparator - the String to search for, may be null
null if null String input
public static String substringAfterLast(String str,
String separator)
Gets the substring after the last occurrence of a separator. The separator is not returned.
A null string input will return null. An empty ("") string
input will return the empty string. An empty or null separator will
return the empty string if the input string is not null.
If nothing is found, the empty string is returned.
StringUtils.substringAfterLast(null, *) = null
StringUtils.substringAfterLast("", *) = ""
StringUtils.substringAfterLast(*, "") = ""
StringUtils.substringAfterLast(*, null) = ""
StringUtils.substringAfterLast("abc", "a") = "bc"
StringUtils.substringAfterLast("abcba", "b") = "a"
StringUtils.substringAfterLast("abc", "c") = ""
StringUtils.substringAfterLast("a", "a") = ""
StringUtils.substringAfterLast("a", "z") = ""
str - the String to get a substring from, may be nullseparator - the String to search for, may be null
null if null String input
public static String substringBeforeLast(String str,
String separator)
Gets the substring before the last occurrence of a separator. The separator is not returned.
A null string input will return null. An empty ("") string
input will return the empty string. An empty or null separator will
return the input string.
If nothing is found, the string input is returned.
StringUtils.substringBeforeLast(null, *) = null
StringUtils.substringBeforeLast("", *) = ""
StringUtils.substringBeforeLast("abcba", "b") = "abc"
StringUtils.substringBeforeLast("abc", "c") = "ab"
StringUtils.substringBeforeLast("a", "a") = ""
StringUtils.substringBeforeLast("a", "z") = "a"
StringUtils.substringBeforeLast("a", null) = "a"
StringUtils.substringBeforeLast("a", "") = "a"
str - the String to get a substring from, may be nullseparator - the String to search for, may be null
null if null String input
public static int countMatches(CharSequence str,
char ch)
Counts how many times the char appears in the given string.
A null or empty ("") String input returns 0.
StringUtils.countMatches(null, *) = 0
StringUtils.countMatches("", *) = 0
StringUtils.countMatches("abba", 0) = 0
StringUtils.countMatches("abba", 'a') = 2
StringUtils.countMatches("abba", 'b') = 2
StringUtils.countMatches("abba", 'x') = 0
str - the CharSequence to check, may be nullch - the char to count
nullpublic static String getRandomString(int length)
public static boolean arraysEqual(Object[] array1,
Object[] array2)
public static String arrayToStringButSkipFirst(Object[] array)
public static String arrayToString(Object[] array)
public static String arrayToString(Object[] array,
String seperateString)
public static String listToString(List<?> lst)
public static String[] joinStringArray(String[] array1,
String[] array2)
public static boolean isCapitalizedString(String str)
public static String toLowerCaseFirstOne(String s)
public static String toUpperCaseFirstOne(String s)
public static boolean isNormalLetters(char c)
public static boolean isInvisibleChar(char c)
public static String formatSQL(String sql)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||