java.lang.Object
io.github.palexdev.materialfx.utils.StringUtils
Utils class for
Strings
.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
containsAll
(String str, String split, String... words) Checks if the given string contains all the specifies words.static boolean
containsAny
(String str, String split, String... words) Checks if the given string contains at least one of the given words.static boolean
containsIgnoreCase
(CharSequence str, CharSequence searchStr) Checks if a CharSequence contains a search CharSequence irrespective of case, handlingnull
.static String
difference
(String str1, String str2) Finds the difference between twoStrings
.static boolean
endsWithIgnoreCase
(String str, String suffix) Checks if the given string ends with the given prefix, ignores case.static int
indexOfDifference
(CharSequence cs1, CharSequence cs2) Finds the index at which twoCharSequences
differ.static String
randAlphabetic
(int length) Generates a random alphabetic string of given lengthstatic String
randAlphanumeric
(int length) Generates a random alphanumeric string of given lengthstatic String
replaceIndex
(String string, int startIndex, int endIndex, String replacement) static String
replaceLast
(String string, String substring, String replacement) Replaces the last occurrence of the given string with a new string.static boolean
startsWithIgnoreCase
(String str, String prefix) Checks if thee given string starts with the specifies prefix, ignores case.static String
timeToHumanReadable
(long elapsedSeconds) A useful method to convert a given elapsed time in seconds to a String.static String
titleCaseWord
(String str)
-
Field Details
-
EMPTY
- See Also:
-
INDEX_NOT_FOUND
public static final int INDEX_NOT_FOUND- See Also:
-
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
difference
Finds the difference between twoStrings
.- Parameters:
str1
- The first Stringstr2
- The second String- Returns:
- the difference between the two given strings
-
indexOfDifference
Finds the index at which twoCharSequences
differ.- Parameters:
cs1
- The first sequencecs2
- The second sequence
-
replaceLast
Replaces the last occurrence of the given string with a new string.- Parameters:
string
- The string to modifysubstring
- The last occurrence to findreplacement
- The replacement- Returns:
- The modified string
-
replaceIndex
-
titleCaseWord
-
containsIgnoreCase
Checks if a CharSequence contains a search CharSequence irrespective of case, handling
null
. Case-insensitivity is defined as byString.equalsIgnoreCase(String)
.A
null
CharSequence will returnfalse
. -
startsWithIgnoreCase
Checks if thee given string starts with the specifies prefix, ignores case. -
endsWithIgnoreCase
Checks if the given string ends with the given prefix, ignores case. -
containsAny
Checks if the given string contains at least one of the given words.- Parameters:
split
- this is the character that will split the input string, seeString.split(String)
-
containsAll
Checks if the given string contains all the specifies words.- Parameters:
split
- this is the character that will split the input string, seeString.split(String)
-
timeToHumanReadable
A useful method to convert a given elapsed time in seconds to a String.- "Just now" if elapsed is less than 60 seconds
- minutes + " minutes ago" if the elapsed seconds is greater than 60 seconds
- hours + " minutes ago" if the elapsed minutes are greater than 60 minutes
- days + " days ago" if the elapsed hours are greater than 24
-
randAlphabetic
Generates a random alphabetic string of given length -
randAlphanumeric
Generates a random alphanumeric string of given length
-