Package panda.utilities
Class StringUtils
java.lang.Object
panda.utilities.StringUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildSpace(int spaces) Generate spacestatic Stringcapitalize(String text) Capitalize characters in string, merged from StringUtils.capitalize [modules - commons-lang:commons-lang3]static booleancontainsCharacter(String text, char... characters) Checks if the specified text contains any character from the specified arraystatic booleancontainsOtherCharacters(String text, char[]... characters) Checks if the specified text contains other characters than these from the specified arraystatic booleanChecks if the specified text contains character other than letter or digitstatic intcountOccurrences(String text, String element) Amount of the occurrences of the specified text in stringstatic StringextractParagraph(String str) Extracts paragraph/indentation from the beginning of the textstatic booleanChecks if the specified text is null or emptystatic StringChecks if the specified text is null or empty, throw exception if it isstatic booleanCheck if the specified string can be parsed as a number Allowed characters: 0-9 - digits x - hexadecimalstatic StringJoin string into the one stringstatic intlastIndexOf(String text, String element, int toIndex) Returns the index within this string of the last occurrence of the specified substringstatic intlastIndexOfBefore(String text, String element, int occurrences) Last index of the element with given amount of last occurrences to ignorestatic Stringstatic StringFaster alternative to String#replacestatic StringreplaceFirst(String text, String pattern, String replacement) Replace the first occurrence of the specified pattern in the textstatic StringreplaceFirst(String text, String pattern, String replacement, int start) Replace the first occurrence of the specified pattern in the textstatic StringreplaceRespectively(String text, String pattern, String... values) Replaces respectively substring of this string that matches the literal target sequence with the specified literal replacement sequence.static StringreplaceRespectivelyAndSoftly(String text, String pattern, String... values) Replaces respectively substring of this string that matches the literal target sequence with the specified literal replacement sequence.static String[]Split text by the specified delimiter (without regex)static String[]splitFirst(String text, String delimiter) Split text by the specified delimiter, but only once (to the first occurrence of the specified delimiter)static booleanstartsWith(String text, Predicate<char[]> filter) Check how the specified text startsstatic StringObject to string with array supportstatic StringTrim the of end of the specified textstatic StringTrim the beginning of the text
-
Field Details
-
EMPTY
Instance of the empty string- See Also:
-
EMPTY_ARRAY
Instance of the empty array of string
-
-
Method Details
-
splitFirst
Split text by the specified delimiter, but only once (to the first occurrence of the specified delimiter)- Parameters:
text- the text to splitdelimiter- the delimiter to search for- Returns:
- array of split text
-
split
Split text by the specified delimiter (without regex)- Parameters:
text- the text to splitdelimiter- the delimiting text- Returns:
- the array of elements
-
lastIndexOfBefore
Last index of the element with given amount of last occurrences to ignore- Parameters:
text- the text to search inelement- the element to search foroccurrences- amount of occurrences to ignore before the element to search for- Returns:
- index of the element, -1 when the element is not found
-
lastIndexOf
Returns the index within this string of the last occurrence of the specified substring- Parameters:
text- the text to searchelement- the substring to search fortoIndex- the previous last index- Returns:
- the index of the last occurrence of the specified substring, or -1 if there is no such occurrence or toIndex is smaller than 1
-
replace
Faster alternative to String#replace- Parameters:
text- the text to search and replace insearchString- the text to search forreplacement- the text to replace with- Returns:
- the resulting text
-
replaceFirst
Replace the first occurrence of the specified pattern in the text- Parameters:
text- the text to search and replace inpattern- the text to search forreplacement- the text to replace with- Returns:
- the processed text
-
replaceFirst
Replace the first occurrence of the specified pattern in the text- Parameters:
text- the text to search and replace inpattern- the text to search forreplacement- the text to replace withstart- position to start searching for- Returns:
- the processed text
-
replaceRespectively
Replaces respectively substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, using the next element of the specified values- Parameters:
text- The sequence of char values to be replace replacement – The replacement sequence of char valuespattern- The pattern to searchvalues- The replacement sequences- Returns:
- the resulting string
- Throws:
IllegalArgumentException- if the amount of patterns is different than the amount of values
-
replaceRespectivelyAndSoftly
Replaces respectively substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, using the next element of the specified values- Parameters:
text- The sequence of char values to be replace replacement – The replacement sequence of char valuespattern- The pattern to searchvalues- The replacement sequences- Returns:
- the resulting string
-
capitalize
Capitalize characters in string, merged from StringUtils.capitalize [modules - commons-lang:commons-lang3]- Parameters:
text- the string to capitalize, may be null- Returns:
- the capitalized string,
nullif null string input
-
startsWith
Check how the specified text starts- Parameters:
text- the text to checkfilter- condition- Returns:
- result of the condition
-
trimStart
Trim the beginning of the text- Parameters:
text- the text to trim- Returns:
- trimmed string
-
trimEnd
Trim the of end of the specified text- Parameters:
text- the text to trim- Returns:
- trimmed string
-
extractParagraph
Extracts paragraph/indentation from the beginning of the text- Parameters:
str- a string to search- Returns:
- whitespaces at the beginning of the specified string
-
buildSpace
Generate space- Parameters:
spaces- number of spaces- Returns:
- generated indentation
-
repeated
-
countOccurrences
Amount of the occurrences of the specified text in string- Parameters:
text- the string to search inelement- the string to search for- Returns:
- amount of the occurrences
-
containsCharacter
Checks if the specified text contains any character from the specified array- Parameters:
text- a string to searchcharacters- searched characters- Returns:
- true if the specified string contains any of the specified characters
-
containsSpecialCharacters
Checks if the specified text contains character other than letter or digit- Parameters:
text- the string to search in- Returns:
- true if the specified string contains a character other than a letter or a digit
-
containsOtherCharacters
Checks if the specified text contains other characters than these from the specified array- Parameters:
text- the string to search in- Returns:
- true if the string contains a character other than the specified in arrays
-
join
Join string into the one string- Parameters:
strings- strings to join- Returns:
- joined string
-
toString
Object to string with array support- Parameters:
object- the object to stringify- Returns:
- object represented by string
-
isNumber
Check if the specified string can be parsed as a number Allowed characters: 0-9 - digits x - hexadecimal . - float- Parameters:
str- string to check- Returns:
- true if the specified text can be a number
-
isEmpty
Checks if the specified text is null or empty, throw exception if it is- Parameters:
text- to checkexceptionMessage- the message is used byIllegalArgumentException- Returns:
- the checked text
-
isEmpty
Checks if the specified text is null or empty- Parameters:
text- to check- Returns:
- true if a specified text is null or empty
-