|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jodd.util.StringUtil
public class StringUtil
Various String utilities.
Field Summary | |
---|---|
static java.lang.String |
WHITESPACE
|
Constructor Summary | |
---|---|
StringUtil()
|
Method Summary | |
---|---|
static java.lang.String |
capitalize(java.lang.String str)
Capitalizes a string, changing the first letter to upper case. |
static java.lang.String |
convertCharset(java.lang.String source,
java.lang.String srcCharsetName,
java.lang.String newCharsetName)
Converts string charsets. |
static int |
count(java.lang.String source,
char c)
|
static int |
count(java.lang.String source,
char c,
int start)
|
static int |
count(java.lang.String source,
java.lang.String sub)
Count substring occurrences in a source string. |
static int |
count(java.lang.String source,
java.lang.String sub,
int start)
|
static int |
countIgnoreCase(java.lang.String source,
java.lang.String sub)
Count substring occurrences in a source string, ignoring case. |
static boolean |
endsWithIgnoreCase(java.lang.String src,
java.lang.String subS)
Tests if this string ends with the specified suffix. |
static int |
endsWithOne(java.lang.String src,
java.lang.String[] dest)
Checks if string ends with at least one string from the provided array. |
static int |
endsWithOneIgnoreCase(java.lang.String src,
java.lang.String[] dest)
Checks if string ends with at least one string from the provided array. |
static boolean |
equals(java.lang.String[] as,
java.lang.String[] as1)
Compares two string arrays. |
static boolean |
equals(java.lang.String s1,
java.lang.String s2)
Compares 2 strings. |
static boolean |
equalsIgnoreCase(java.lang.String[] as,
java.lang.String[] as1)
Compares two string arrays. |
static int |
equalsOne(java.lang.String src,
java.lang.String[] dest)
Compares string with at least one from the provided array. |
static int |
equalsOneIgnoreCase(java.lang.String src,
java.lang.String[] dest)
Compares string with at least one from the provided array, ignoring case. |
static int |
indexOf(java.lang.String src,
char c,
int startIndex,
int endIndex)
Finds the first occurrence of a character in the given source but within limited range (start, end]. |
static int[] |
indexOf(java.lang.String s,
java.lang.String[] arr)
Finds the very first index of a substring from the specified array. |
static int[] |
indexOf(java.lang.String s,
java.lang.String[] arr,
int start)
Finds the very first index of a substring from the specified array. |
static int |
indexOf(java.lang.String src,
java.lang.String sub,
int startIndex,
int endIndex)
Finds first occurrence of a substring in the given source but within limited range [start, end). |
static int |
indexOfChars(java.lang.String string,
char[] chars)
|
static int |
indexOfChars(java.lang.String string,
char[] chars,
int startindex)
Returns the very first index of any char from provided string, starting from specified index offset. |
static int |
indexOfChars(java.lang.String string,
java.lang.String chars)
|
static int |
indexOfChars(java.lang.String string,
java.lang.String chars,
int startindex)
Returns the very first index of any char from provided string, starting from specified index offset. |
static int |
indexOfIgnoreCase(java.lang.String src,
java.lang.String subS)
Finds first index of a substring in the given source string with ignored case. |
static int[] |
indexOfIgnoreCase(java.lang.String s,
java.lang.String[] arr)
Finds the very first index of a substring from the specified array. |
static int[] |
indexOfIgnoreCase(java.lang.String s,
java.lang.String[] arr,
int start)
Finds the very first index of a substring from the specified array. |
static int |
indexOfIgnoreCase(java.lang.String src,
java.lang.String subS,
int startIndex)
Finds first index of a substring in the given source string with ignored case. |
static int |
indexOfIgnoreCase(java.lang.String src,
java.lang.String sub,
int startIndex,
int endIndex)
Finds first index of a substring in the given source string and range with ignored case. |
static int[] |
indexOfRegion(java.lang.String string,
java.lang.String leftBoundary,
java.lang.String rightBoundary)
|
static int[] |
indexOfRegion(java.lang.String string,
java.lang.String leftBoundary,
java.lang.String rightBoundary,
char escape)
|
static int[] |
indexOfRegion(java.lang.String string,
java.lang.String leftBoundary,
java.lang.String rightBoundary,
char escape,
int offset)
Returns indexes of the first string region. |
static int[] |
indexOfRegion(java.lang.String string,
java.lang.String leftBoundary,
java.lang.String rightBoundary,
int offset)
Returns indexes of the first region without escaping character. |
static boolean |
isBlank(java.lang.String string)
Determines if a string is blank ( null or trimmed empty) |
static boolean |
isEmpty(java.lang.String string)
Determines if a string is empty ( null or empty). |
static boolean |
isNotEmpty(java.lang.String string)
Determines if a string is not empty. |
static int |
lastIndexOf(java.lang.String src,
char c,
int startIndex,
int endIndex)
Finds last index of a character in the given source string in specified range [end, start] |
static int[] |
lastIndexOf(java.lang.String s,
java.lang.String[] arr)
Finds the very last index of a substring from the specified array. |
static int[] |
lastIndexOf(java.lang.String s,
java.lang.String[] arr,
int fromIndex)
Finds the very last index of a substring from the specified array. |
static int |
lastIndexOf(java.lang.String src,
java.lang.String sub,
int startIndex,
int endIndex)
Finds last index of a substring in the given source string in specified range [end, start] See indexOf(String, String, int, int) for details about the speed. |
static int |
lastIndexOfIgnoreCase(java.lang.String s,
java.lang.String subS)
Finds last index of a substring in the given source string with ignored case. |
static int[] |
lastIndexOfIgnoreCase(java.lang.String s,
java.lang.String[] arr)
Finds the very last index of a substring from the specified array. |
static int[] |
lastIndexOfIgnoreCase(java.lang.String s,
java.lang.String[] arr,
int fromIndex)
Finds the very last index of a substring from the specified array. |
static int |
lastIndexOfIgnoreCase(java.lang.String src,
java.lang.String subS,
int startIndex)
Finds last index of a substring in the given source string with ignored case. |
static int |
lastIndexOfIgnoreCase(java.lang.String src,
java.lang.String sub,
int startIndex,
int endIndex)
Finds last index of a substring in the given source string with ignored case in specified range. |
static java.lang.String |
remove(java.lang.String src,
char chars)
Removes a single character from string. |
static java.lang.String |
remove(java.lang.String s,
java.lang.String sub)
Removes all substring occurrences from the string. |
static java.lang.String |
removeChars(java.lang.String src,
char[] chars)
Removes set of characters from string. |
static java.lang.String |
removeChars(java.lang.String src,
java.lang.String chars)
Removes all characters contained in provided string. |
static java.lang.String |
replace(java.lang.String s,
char sub,
char with)
Replaces all occurrences of a character in a string. |
static java.lang.String |
replace(java.lang.String s,
java.lang.String[] sub,
java.lang.String[] with)
Replaces many substring at once. |
static java.lang.String |
replace(java.lang.String s,
java.lang.String sub,
java.lang.String with)
Replaces the occurrences of a certain pattern in a string with a replacement string. |
static java.lang.String |
replaceFirst(java.lang.String s,
char sub,
char with)
Replaces the very first occurrence of a character in a string. |
static java.lang.String |
replaceFirst(java.lang.String s,
java.lang.String sub,
java.lang.String with)
Replaces the very first occurrence of a substring with supplied string. |
static java.lang.String |
replaceIgnoreCase(java.lang.String s,
java.lang.String[] sub,
java.lang.String[] with)
Replaces many substring at once. |
static java.lang.String |
replaceLast(java.lang.String s,
char sub,
char with)
Replaces the very last occurrence of a character in a string. |
static java.lang.String |
replaceLast(java.lang.String s,
java.lang.String sub,
java.lang.String with)
Replaces the very last occurrence of a substring with supplied string. |
static java.lang.String[] |
split(java.lang.String src,
java.lang.String delimeter)
Splits a string in several parts (tokens) that are separated by delimiter. |
static java.lang.String[] |
splitc(java.lang.String src,
char delimiter)
Splits a string in several parts (tokens) that are separated by single delimiter characters. |
static java.lang.String[] |
splitc(java.lang.String src,
java.lang.String d)
Splits a string in several parts (tokens) that are separated by delimiter characters. |
static boolean |
startsWithIgnoreCase(java.lang.String src,
java.lang.String subS)
Tests if this string starts with the specified prefix with ignored case. |
static boolean |
startsWithIgnoreCase(java.lang.String src,
java.lang.String subS,
int startIndex)
Tests if this string starts with the specified prefix with ignored case and with the specified prefix beginning a specified index. |
static int |
startsWithOne(java.lang.String src,
java.lang.String[] dest)
Checks if string starts with at least one string from the provided array. |
static int |
startsWithOneIgnoreCase(java.lang.String src,
java.lang.String[] dest)
Checks if string starts with at least one string from the provided array. |
static java.lang.String |
toNotNullString(java.lang.Object obj)
Converts safely an object to a string. |
static java.lang.String |
toString(java.lang.Object obj)
Converts safely an object to a string. |
static java.lang.String[] |
toStringArray(java.lang.Object obj)
Converts an object to a String Array. |
static void |
trim(java.lang.String[] strings)
Trims array of strings. |
static java.lang.String |
trimNonEmpty(java.lang.String string)
Trims string where empty strings are returned as a null . |
static void |
trimNonEmpty(java.lang.String[] strings)
Trims array of strings where empty strings are nulled. |
static java.lang.String |
truncate(java.lang.String string,
int length)
Sets the maximum length of the string. |
static java.lang.String |
uncapitalize(java.lang.String str)
Uncapitalizes a String , changing the first letter to
lower case. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String WHITESPACE
Constructor Detail |
---|
public StringUtil()
Method Detail |
---|
public static java.lang.String replace(java.lang.String s, java.lang.String sub, java.lang.String with)
s
- string to be inspectedsub
- string pattern to be replacedwith
- string that should go where the pattern waspublic static java.lang.String replace(java.lang.String s, char sub, char with)
s
- input stringsub
- character to replacewith
- character to replace withpublic static java.lang.String replaceFirst(java.lang.String s, java.lang.String sub, java.lang.String with)
s
- source stringsub
- substring to replacewith
- substring to replace withpublic static java.lang.String replaceFirst(java.lang.String s, char sub, char with)
s
- stringsub
- char to replacewith
- char to replace withpublic static java.lang.String replaceLast(java.lang.String s, java.lang.String sub, java.lang.String with)
s
- source stringsub
- substring to replacewith
- substring to replace withpublic static java.lang.String replaceLast(java.lang.String s, char sub, char with)
s
- stringsub
- char to replacewith
- char to replace withpublic static java.lang.String remove(java.lang.String s, java.lang.String sub)
s
- source stringsub
- substring to removepublic static java.lang.String removeChars(java.lang.String src, java.lang.String chars)
src
- source stringchars
- string containing characters to removepublic static java.lang.String removeChars(java.lang.String src, char[] chars)
src
- stringchars
- character to removepublic static java.lang.String remove(java.lang.String src, char chars)
src
- source stringchars
- character to removepublic static boolean equals(java.lang.String s1, java.lang.String s2)
null
, false
is returned. if
both string are null
, true
is returned.
s1
- first string to compares2
- second string
true
if strings are equal, otherwise false
public static boolean isEmpty(java.lang.String string)
null
or empty).
public static boolean isBlank(java.lang.String string)
null
or trimmed empty).,
public static boolean isNotEmpty(java.lang.String string)
public static java.lang.String toString(java.lang.Object obj)
null
it will be
not converted.
public static java.lang.String toNotNullString(java.lang.Object obj)
null
a empty
string is returned.
public static java.lang.String[] toStringArray(java.lang.Object obj)
public static java.lang.String capitalize(java.lang.String str)
str
- string to capitalize, may be nulluncapitalize(String)
public static java.lang.String uncapitalize(java.lang.String str)
String
, changing the first letter to
lower case. No other letters are changed.
str
- the String to uncapitalize, may be null
null
if nullcapitalize(String)
public static java.lang.String truncate(java.lang.String string, int length)
public static java.lang.String[] split(java.lang.String src, java.lang.String delimeter)
Method is much, much faster then regexp String.split()
,
and a bit faster then StringTokenizer
.
src
- string to splitdelimeter
- split delimiter
public static java.lang.String[] splitc(java.lang.String src, java.lang.String d)
src
- source to examined
- string with delimiter characters
public static java.lang.String[] splitc(java.lang.String src, char delimiter)
src
- source to examinedelimiter
- delimiter character
public static int indexOf(java.lang.String src, java.lang.String sub, int startIndex, int endIndex)
String.indexOf(String, int)
is much faster (since it uses char[] value directly) and should be used when no range is needed.
src
- source string for examinationsub
- substring to findstartIndex
- starting indexendIndex
- ending index
public static int indexOf(java.lang.String src, char c, int startIndex, int endIndex)
public static int indexOfIgnoreCase(java.lang.String src, java.lang.String subS)
src
- source string for examinationsubS
- substring to find
indexOfIgnoreCase(String, String, int)
public static int indexOfIgnoreCase(java.lang.String src, java.lang.String subS, int startIndex)
src
- source string for examinationsubS
- substring to findstartIndex
- starting index from where search begins
public static int indexOfIgnoreCase(java.lang.String src, java.lang.String sub, int startIndex, int endIndex)
src
- source string for examinationsub
- substring to findstartIndex
- starting index from where search beginsendIndex
- endint index
indexOfIgnoreCase(String, String, int)
public static int lastIndexOfIgnoreCase(java.lang.String s, java.lang.String subS)
s
- source stringsubS
- substring to find
indexOfIgnoreCase(String, String, int)
,
lastIndexOfIgnoreCase(String, String, int)
public static int lastIndexOfIgnoreCase(java.lang.String src, java.lang.String subS, int startIndex)
src
- source string for examinationsubS
- substring to findstartIndex
- starting index from where search begins
indexOfIgnoreCase(String, String, int)
public static int lastIndexOfIgnoreCase(java.lang.String src, java.lang.String sub, int startIndex, int endIndex)
src
- source to examinesub
- substring to findstartIndex
- starting indexendIndex
- end index
public static int lastIndexOf(java.lang.String src, java.lang.String sub, int startIndex, int endIndex)
indexOf(String, String, int, int)
for details about the speed.
src
- source to examinesub
- substring to findstartIndex
- starting indexendIndex
- end index
public static int lastIndexOf(java.lang.String src, char c, int startIndex, int endIndex)
public static boolean startsWithIgnoreCase(java.lang.String src, java.lang.String subS)
src
- source string to testsubS
- starting substring
true
if the character sequence represented by the argument is
a prefix of the character sequence represented by this string;
false
otherwise.public static boolean startsWithIgnoreCase(java.lang.String src, java.lang.String subS, int startIndex)
src
- source string to testsubS
- starting substringstartIndex
- index from where to test
true
if the character sequence represented by the argument is
a prefix of the character sequence represented by this string;
false
otherwise.public static boolean endsWithIgnoreCase(java.lang.String src, java.lang.String subS)
src
- String to testsubS
- suffix
true
if the character sequence represented by the argument is
a suffix of the character sequence represented by this object;
false
otherwise.public static int count(java.lang.String source, java.lang.String sub)
source
- source stringsub
- substring to count
public static int count(java.lang.String source, java.lang.String sub, int start)
public static int count(java.lang.String source, char c)
public static int count(java.lang.String source, char c, int start)
public static int countIgnoreCase(java.lang.String source, java.lang.String sub)
source
- source stringsub
- substring to count
public static int[] indexOf(java.lang.String s, java.lang.String[] arr)
s
- source stringarr
- string array
public static int[] indexOf(java.lang.String s, java.lang.String[] arr, int start)
s
- source stringarr
- string arraystart
- starting position
public static int[] indexOfIgnoreCase(java.lang.String s, java.lang.String[] arr)
s
- source stringarr
- string array
public static int[] indexOfIgnoreCase(java.lang.String s, java.lang.String[] arr, int start)
s
- source stringarr
- string arraystart
- starting position
public static int[] lastIndexOf(java.lang.String s, java.lang.String[] arr)
s
- source stringarr
- string array
public static int[] lastIndexOf(java.lang.String s, java.lang.String[] arr, int fromIndex)
s
- source stringarr
- string arrayfromIndex
- starting position
public static int[] lastIndexOfIgnoreCase(java.lang.String s, java.lang.String[] arr)
s
- source stringarr
- string array
public static int[] lastIndexOfIgnoreCase(java.lang.String s, java.lang.String[] arr, int fromIndex)
s
- source stringarr
- string arrayfromIndex
- starting position
public static boolean equals(java.lang.String[] as, java.lang.String[] as1)
as
- first string arrayas1
- second string array
true
if all array elements matchespublic static boolean equalsIgnoreCase(java.lang.String[] as, java.lang.String[] as1)
as
- first string arrayas1
- second string array
public static java.lang.String replace(java.lang.String s, java.lang.String[] sub, java.lang.String[] with)
s
- source stringsub
- substrings arraywith
- replace with array
public static java.lang.String replaceIgnoreCase(java.lang.String s, java.lang.String[] sub, java.lang.String[] with)
s
- source stringsub
- substrings arraywith
- replace with array
public static int equalsOne(java.lang.String src, java.lang.String[] dest)
-1
is returned.
public static int equalsOneIgnoreCase(java.lang.String src, java.lang.String[] dest)
-1
is returned.
public static int startsWithOne(java.lang.String src, java.lang.String[] dest)
-1
is returned.
public static int startsWithOneIgnoreCase(java.lang.String src, java.lang.String[] dest)
-1
is returned.
public static int endsWithOne(java.lang.String src, java.lang.String[] dest)
-1
is returned.
public static int endsWithOneIgnoreCase(java.lang.String src, java.lang.String[] dest)
-1
is returned.
public static int indexOfChars(java.lang.String string, java.lang.String chars)
public static int indexOfChars(java.lang.String string, java.lang.String chars, int startindex)
-1
if nothing found.
public static int indexOfChars(java.lang.String string, char[] chars)
public static int indexOfChars(java.lang.String string, char[] chars, int startindex)
-1
if nothing found.
public static void trim(java.lang.String[] strings)
public static void trimNonEmpty(java.lang.String[] strings)
trimNonEmpty(String)
public static java.lang.String trimNonEmpty(java.lang.String string)
null
.
public static int[] indexOfRegion(java.lang.String string, java.lang.String leftBoundary, java.lang.String rightBoundary)
indexOfRegion(String, String, String, int)
public static int[] indexOfRegion(java.lang.String string, java.lang.String leftBoundary, java.lang.String rightBoundary, int offset)
indexOfRegion(String, String, String, char, int)
public static int[] indexOfRegion(java.lang.String string, java.lang.String leftBoundary, java.lang.String rightBoundary, char escape)
indexOfRegion(String, String, String, char, int)
public static int[] indexOfRegion(java.lang.String string, java.lang.String leftBoundary, java.lang.String rightBoundary, char escape, int offset)
Escape character may be used to prefix boundaries so they can be ignored.
If region is not founded, null
is returned.
public static java.lang.String convertCharset(java.lang.String source, java.lang.String srcCharsetName, java.lang.String newCharsetName) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |