Package com.helger.base.string
Class StringHelper
java.lang.Object
com.helger.base.string.StringHelper
Simple string utility methods, originally in StringHelper.
- Since:
- v12.0.0
- Author:
- Philip Helger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendQuoted(Appendable aTarget, String sSource) Append the provided string quoted or unquoted if it isnull.static voidappendQuoted(StringBuilder aTarget, String sSource) Append the provided string quoted or unquoted if it isnull.static booleanCheck if cSearch is contained within sText.static booleanCheck if sSearch is contained within sText.static booleancontainsAny(char[] aInput, char[] aSearchChars) Check if any of the passed searched characters is contained in the input char array.static booleancontainsAny(CharSequence aCS, ICharPredicate aFilter) Check if the passedCharSequencecontains any character matching the provided filter.static booleancontainsAny(String sInput, char[] aSearchChars) Check if any of the passed searched characters in contained in the input string.static booleancontainsAny(String sStr, ICharPredicate aFilter) Check if the passedStringcontains any character matching the provided filter.static booleancontainsIgnoreCase(String sText, char cSearch, Locale aSortLocale) Check if cSearch is contained within sText ignoring case.static booleancontainsIgnoreCase(String sText, String sSearch, Locale aSortLocale) Check if sSearch is contained within sText ignoring case.static booleancontainsNone(CharSequence aCS, ICharPredicate aFilter) Check if the passedCharSequencecontains no character matching the provided filter.static booleancontainsNone(String sStr, ICharPredicate aFilter) Check if the passedStringcontains no character matching the provided filter.static booleancontainsOnly(CharSequence aCS, ICharPredicate aFilter) Check if the passedCharSequencecontains only characters matching the provided filter.static booleancontainsOnly(String sStr, ICharPredicate aFilter) Check if the passedStringcontains only characters matching the provided filter.static booleanendsWith(CharSequence aCS, char c) static booleanendsWith(CharSequence aCS, CharSequence aSearch) static booleanstatic booleanendsWithAny(CharSequence aCS, char[] aChars) static booleanendsWithIgnoreCase(CharSequence aCS, char c) static booleanendsWithIgnoreCase(String sStr, String sSearch) static voidSplit the provided string by the provided separator and invoke the consumer for each matched element.static voidSplit the provided string by the provided separator and invoke the consumer for each matched element.static voidSplit the provided string by the provided separator and invoke the consumer for each matched element.static voidSplit the provided string by the provided separator and invoke the consumer for each matched element.static StringgetConcatenatedOnDemand(String sFront, char cSep, String sEnd) Concatenate the strings sFront and sEnd by the "cSep" separator.static StringgetConcatenatedOnDemand(String sFront, String sEnd) Concatenate the strings sFront and sEnd.static StringgetConcatenatedOnDemand(String sFront, String sSep, String sEnd) Concatenate the strings sFront and sEnd by the "sSep" string.static StringgetCutAfterLength(String sValue, int nMaxLength) static StringgetCutAfterLength(String sValue, int nMaxLength, String sNewSuffix) getExploded(char cSep, String sElements) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.getExploded(char cSep, String sElements, int nMaxItems) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.static <COLLTYPE extends Collection<String>>
COLLTYPEgetExploded(char cSep, String sElements, int nMaxItems, COLLTYPE aCollection) Take a concatenated String and return the passed Collection of all elements in the passed string, using specified separator string.getExploded(String sSep, String sElements) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.getExploded(String sSep, String sElements, int nMaxItems) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.static <COLLTYPE extends Collection<String>>
COLLTYPEgetExploded(String sSep, String sElements, int nMaxItems, COLLTYPE aCollection) Take a concatenated String and return the passed Collection of all elements in the passed string, using specified separator string.static String[]getExplodedArray(char cSep, String sElements) Take a concatenated String and return the passed String array of all elements in the passed string, using specified separator char.static String[]getExplodedArray(char cSep, String sElements, int nMaxItems) Take a concatenated String and return the passed String array of all elements in the passed string, using specified separator char.static LinkedHashSet<String> getExplodedToOrderedSet(String sSep, String sElements) Take a concatenated String and return an orderedLinkedHashSetof all elements in the passed string, using specified separator string.getExplodedToSet(String sSep, String sElements) Take a concatenated String and return aSetof all elements in the passed string, using specified separator string.getExplodedToSortedSet(String sSep, String sElements) Take a concatenated String and return a sortedTreeSetof all elements in the passed string, using specified separator string.static chargetFirstChar(char[] aChars) Get the first character of the passed arraystatic chargetFirstChar(CharSequence aCS) Get the first character of the passed character sequencestatic StringgetFirstToken(String sStr, char cSearch) Get the first token up to (and excluding) the separating character.static StringgetFirstToken(String sStr, String sSearch) Get the first token up to (and excluding) the separating string.static StringgetFromFirstExcl(String sStr, char cSearch) Get everything from the string from and excluding the first passed char.static StringgetFromFirstExcl(String sStr, String sSearch) Get everything from the string from and excluding the passed string.static StringgetFromFirstIncl(String sStr, char cSearch) Get everything from the string from and including the first passed char.static StringgetFromFirstIncl(String sStr, String sSearch) Get everything from the string from and including the passed string.static StringgetFromLastExcl(String sStr, char cSearch) Get everything from the string from and excluding the first passed char.static StringgetFromLastExcl(String sStr, String sSearch) Get everything from the string from and excluding the passed string.static StringgetFromLastIncl(String sStr, char cSearch) Get everything from the string from and including the first passed char.static StringgetFromLastIncl(String sStr, String sSearch) Get everything from the string from and including the passed string.static intgetIndexOf(String sText, char cSearch) Get the first index of cSearch within sText.static intgetIndexOf(String sText, int nFromIndex, char cSearch) Get the first index of cSearch within sText starting at index nFromIndex.static intgetIndexOf(String sText, int nFromIndex, String sSearch) Get the first index of sSearch within sText starting at index nFromIndex.static intgetIndexOf(String sText, String sSearch) Get the first index of sSearch within sText.static intgetIndexOfIgnoreCase(String sText, char cSearch, Locale aSortLocale) Get the first index of cSearch within sText ignoring case.static intgetIndexOfIgnoreCase(String sText, int nFromIndex, char cSearch, Locale aSortLocale) Get the first index of cSearch within sText ignoring case starting at index nFromIndex.static intgetIndexOfIgnoreCase(String sText, int nFromIndex, String sSearch, Locale aSortLocale) Get the first index of sSearch within sText ignoring case starting at index nFromIndex.static intgetIndexOfIgnoreCase(String sText, String sSearch, Locale aSortLocale) Get the first index of sSearch within sText ignoring case.static chargetLastChar(char[] aChars) Get the last character of the passed arraystatic chargetLastChar(CharSequence aCS) Get the last character of the passed character sequencestatic intgetLastIndexOf(String sText, char cSearch) Get the last index of cSearch within sText.static intgetLastIndexOf(String sText, int nFromIndex, char cSearch) Get the last index of cSearch within sText starting at index nFromIndex.static intgetLastIndexOf(String sText, int nFromIndex, String sSearch) Get the last index of sSearch within sText starting at index nFromIndex.static intgetLastIndexOf(String sText, String sSearch) Get the last index of sSearch within sText.static intgetLastIndexOfIgnoreCase(String sText, char cSearch, Locale aSortLocale) Get the last index of cSearch within sText ignoring case.static intgetLastIndexOfIgnoreCase(String sText, int nFromIndex, char cSearch, Locale aSortLocale) Get the last index of cSearch within sText ignoring case starting at index nFromIndex.static intgetLastIndexOfIgnoreCase(String sText, int nFromIndex, String sSearch, Locale aSortLocale) Get the last index of sSearch within sText ignoring case starting at index nFromIndex.static intgetLastIndexOfIgnoreCase(String sText, String sSearch, Locale aSortLocale) Get the last index of sSearch within sText ignoring case.static StringgetLastToken(String sStr, char cSearch) Get the last token from (and excluding) the separating character.static StringgetLastToken(String sStr, String sSearch) Get the last token from (and excluding) the separating string.static StringgetLeadingZero(int nValue, int nChars) static StringgetLeadingZero(long nValue, int nChars) static StringgetLeadingZero(Byte aValue, int nChars) static StringgetLeadingZero(Integer aValue, int nChars) static StringgetLeadingZero(Long aValue, int nChars) static StringgetLeadingZero(Short aValue, int nChars) static StringgetLeadingZero(String sValue, int nChars) static intgetLength(CharSequence aCS) Get the length of the passed character sequence.static CharSequencegetNotEmpty(CharSequence s, CharSequence sDefaultIfEmpty) Get the passed char sequence but never return an empty char sequence.static CharSequencegetNotEmpty(CharSequence s, Supplier<? extends CharSequence> aDefaultIfEmpty) Get the passed char sequence but never return an empty char sequence.static StringgetNotEmpty(String s, String sDefaultIfEmpty) Get the passed string but never return an empty string.static StringgetNotEmpty(String s, Supplier<String> aDefaultIfEmpty) Get the passed string but never return an empty string.static CharSequenceGet the passedCharSequencebut never returnnull.static CharSequencegetNotNull(CharSequence s, CharSequence sDefaultIfNull) Get the passedCharSequencebut never returnnull.static CharSequencegetNotNull(CharSequence s, Supplier<? extends CharSequence> aDefaultIfNull) Get the passedCharSequencebut never returnnull.static StringgetNotNull(String s) Get the passed string but never returnnull.static StringgetNotNull(String s, String sDefaultIfNull) Get the passed string but never returnnull.static StringgetNotNull(String s, Supplier<String> aDefaultIfNull) Get the passed string but never returnnull.static StringGet the provided string quoted or unquoted if it isnull.static StringgetRepeated(char cElement, int nRepeats) Get the passed string element repeated for a certain number of times.static StringgetRepeated(String sElement, int nRepeats) Get the passed string element repeated for a certain number of times.static StringgetReverse(String sStr) static StringgetToString(Object aObject) Convert the passed object to a string using theObject.toString()method.static StringgetToString(Object aObject, String sNullValue) Convert the passed object to a string using theObject.toString()method or otherwise return the passed default value.static StringgetUntilFirstExcl(String sStr, char cSearch) Get everything from the string up to and excluding first the passed char.static StringgetUntilFirstExcl(String sStr, String sSearch) Get everything from the string up to and excluding the first passed string.static StringgetUntilFirstIncl(String sStr, char cSearch) Get everything from the string up to and including the first passed char.static StringgetUntilFirstIncl(String sStr, String sSearch) Get everything from the string up to and including the first passed string.static StringgetUntilLastExcl(String sStr, char cSearch) Get everything from the string up to and excluding first the passed char.static StringgetUntilLastExcl(String sStr, String sSearch) Get everything from the string up to and excluding the first passed string.static StringgetUntilLastIncl(String sStr, char cSearch) Get everything from the string up to and including the first passed char.static StringgetUntilLastIncl(String sStr, String sSearch) Get everything from the string up to and including the first passed string.static StringgetWithLeading(int nValue, int nMinLen, char cFront) Get a string that is filled at the beginning with the passed character until the minimum length is reached.static StringgetWithLeading(long nValue, int nMinLen, char cFront) Get a string that is filled at the beginning with the passed character until the minimum length is reached.static StringgetWithLeading(String sSrc, int nMinLen, char cFront) Get a string that is filled at the beginning with the passed character until the minimum length is reached.static StringgetWithoutAnySpaces(String sStr) Get the passed string where all spaces (white spaces or unicode spaces) have been removed.static StringgetWithoutLeadingChar(String sStr) Get the passed string without the first char.static StringgetWithoutLeadingChars(String sStr, int nCount) Get the passed string without the specified number of leading chars.static StringgetWithoutTrailingChar(String sStr) Get the passed string without the last char.static StringgetWithoutTrailingChars(String sStr, int nCount) Get the passed string without the specified number of trailing chars.static StringgetWithTrailing(String sSrc, int nMinLen, char cEnd) Get a string that is filled at the end with the passed character until the minimum length is reached.static booleanhasNoText(CharSequence aCS) Deprecated, for removal: This API element is subject to removal in a future version.static booleanDeprecated, for removal: This API element is subject to removal in a future version.UseisEmpty(String)insteadstatic booleanhasText(CharSequence aCS) Deprecated, for removal: This API element is subject to removal in a future version.UseisNotEmpty(CharSequence)insteadstatic booleanDeprecated, for removal: This API element is subject to removal in a future version.UseisNotEmpty(String)insteadstatic booleanDeprecated, for removal: This API element is subject to removal in a future version.UseisNotEmptyAfterTrim(String)insteadstatic booleanCheck if the passed character sequence is only whitespace or not.static booleanisEmpty(CharSequence aCS) Check if the string isnullor empty.static booleanCheck if the string isnullor empty.static booleanCheck if the string isnullor empty after trimming.static booleanisNotEmpty(CharSequence aCS) Check if the string contains any char.static booleanisNotEmpty(String sStr) Check if the string contains any char.static booleanCheck if the string neithernullnor empty after trimming.static voiditerateChars(String sInputString, ICharConsumer aConsumer) Iterate all characters and pass them to the provided consumer.static voiditerateCodePoints(String sInputString, IntConsumer aConsumer) Iterate all code points and pass them to the provided consumer.static booleanstartsWith(CharSequence aCS, char c) static booleanstartsWith(CharSequence aCS, CharSequence aSearch) static booleanstartsWith(String sStr, String sSearch) static booleanstartsWithAny(CharSequence aCS, char[] aChars) static booleanstartsWithIgnoreCase(CharSequence aCS, char c) static booleanstartsWithIgnoreCase(String sStr, String sSearch) static StringTrim the passed string, if it is notnull.static StringTrim the passed tail from the source value.static StringTrim the passed tail from the source value.static StringTrim the passed tail from the source value.static StringtrimEndRepeatedly(String sSrc, char cTail) static StringtrimEndRepeatedly(String sSrc, String sTail) static StringRemove any leading whitespaces from the passed string.static StringTrim the passed lead from the source value.static StringTrim the passed lead from the source value.static StringTrim the passed lead from the source value.static StringtrimStartAndEnd(String sSrc, char cValueToTrim) Trim the passed lead and tail from the source value.static StringtrimStartAndEnd(String sSrc, char cLead, char cTail) Trim the passed lead and tail from the source value.static StringtrimStartAndEnd(String sSrc, String sValueToTrim) Trim the passed lead and tail from the source value.static StringtrimStartAndEnd(String sSrc, String sLead, String sTail) Trim the passed lead and tail from the source value.static StringtrimStartRepeatedly(String sSrc, char cLead) static StringtrimStartRepeatedly(String sSrc, String sLead) static StringRemove any trailing whitespaces from the passed string.
-
Constructor Details
-
StringHelper
protected StringHelper()
-
-
Method Details
-
isEmpty
Check if the string isnullor empty.- Parameters:
aCS- The character sequence to check. May benull.- Returns:
trueif the string isnullor empty,falseotherwise- Since:
- 10.1.8
-
isEmpty
Check if the string isnullor empty.- Parameters:
sStr- The string to check. May benull.- Returns:
trueif the string isnullor empty,falseotherwise- Since:
- 10.1.8
-
isEmptyAfterTrim
Check if the string isnullor empty after trimming.- Parameters:
s- The string to check. May benull.- Returns:
trueif the string isnullor empty or consists only of whitespaces,falseotherwise- Since:
- 10.1.8
-
isNotEmpty
Check if the string contains any char.- Parameters:
aCS- The character sequence to check. May benull.- Returns:
trueif the string contains at least one,falseotherwise- Since:
- 10.1.8
-
isNotEmpty
Check if the string contains any char.- Parameters:
sStr- The string to check. May benull.- Returns:
trueif the string contains at least one char,falseotherwise- Since:
- 10.1.8
-
isNotEmptyAfterTrim
Check if the string neithernullnor empty after trimming.- Parameters:
s- The string to check. May benull.- Returns:
trueif the string is neithernullnor empty nor consists only of whitespaces,falseotherwise- Since:
- 10.1.8
-
hasNoText
@Deprecated(forRemoval=true, since="12.0.0") public static boolean hasNoText(@Nullable CharSequence aCS) Deprecated, for removal: This API element is subject to removal in a future version.UseisEmpty(CharSequence)insteadCheck if the string isnullor empty.- Parameters:
aCS- The character sequence to check. May benull.- Returns:
trueif the string isnullor empty,falseotherwise
-
hasNoText
Deprecated, for removal: This API element is subject to removal in a future version.UseisEmpty(String)insteadCheck if the string isnullor empty.- Parameters:
sStr- The string to check. May benull.- Returns:
trueif the string isnullor empty,falseotherwise
-
hasText
@Deprecated(forRemoval=true, since="12.0.0") public static boolean hasText(@Nullable CharSequence aCS) Deprecated, for removal: This API element is subject to removal in a future version.UseisNotEmpty(CharSequence)insteadCheck if the string contains any char.- Parameters:
aCS- The character sequence to check. May benull.- Returns:
trueif the string contains at least one,falseotherwise
-
hasText
Deprecated, for removal: This API element is subject to removal in a future version.UseisNotEmpty(String)insteadCheck if the string contains any char.- Parameters:
sStr- The string to check. May benull.- Returns:
trueif the string contains at least one char,falseotherwise
-
hasTextAfterTrim
@Deprecated(forRemoval=true, since="12.0.0") public static boolean hasTextAfterTrim(@Nullable String s) Deprecated, for removal: This API element is subject to removal in a future version.UseisNotEmptyAfterTrim(String)insteadCheck if the string neithernullnor empty after trimming.- Parameters:
s- The string to check. May benull.- Returns:
trueif the string is neithernullnor empty nor consists only of whitespaces,falseotherwise
-
getLength
Get the length of the passed character sequence.- Parameters:
aCS- The character sequence who's length is to be determined. May benull.- Returns:
- 0 if the parameter is
null, its length otherwise. - See Also:
-
getNotNull
Get the passed string but never returnnull. If the passed parameter isnullan empty string is returned.- Parameters:
s- The parameter to be notnull.- Returns:
- An empty string if the passed parameter is
null, the passed string otherwise.
-
getNotNull
Get the passed string but never returnnull. If the passed parameter isnullthe second parameter is returned.- Parameters:
s- The parameter to be notnull.sDefaultIfNull- The value to be used if the first parameter isnull. May benullbut in this case the call to this method is obsolete.- Returns:
- The passed default value if the string is
null, otherwise the input string.
-
getNotNull
@Nullable public static String getNotNull(@Nullable String s, @Nonnull Supplier<String> aDefaultIfNull) Get the passed string but never returnnull. If the passed parameter isnullthe second parameter is returned.- Parameters:
s- The parameter to be notnull.aDefaultIfNull- The value supplier to be used if the first parameter isnull. May not benull.- Returns:
- The passed default value if the string is
null, otherwise the input string. - Since:
- 10.2.0
-
getNotNull
Get the passedCharSequencebut never returnnull. If the passed parameter isnullan empty string is returned.- Parameters:
s- The parameter to be notnull.- Returns:
- An empty string if the passed parameter is
null, the passedCharSequenceotherwise.
-
getNotNull
@Nullable public static CharSequence getNotNull(@Nullable CharSequence s, @Nullable CharSequence sDefaultIfNull) Get the passedCharSequencebut never returnnull. If the passed parameter isnullthe second parameter is returned.- Parameters:
s- The parameter to be notnull.sDefaultIfNull- The value to be used if the first parameter isnull. May benullbut in this case the call to this method is obsolete.- Returns:
- The passed default value if the string is
null, otherwise the inputCharSequence.
-
getNotNull
@Nullable public static CharSequence getNotNull(@Nullable CharSequence s, @Nonnull Supplier<? extends CharSequence> aDefaultIfNull) Get the passedCharSequencebut never returnnull. If the passed parameter isnullthe second parameter is returned.- Parameters:
s- The parameter to be notnull.aDefaultIfNull- The value supplier to be used if the first parameter isnull. May not benull.- Returns:
- The passed default value if the string is
null, otherwise the inputCharSequence. - Since:
- 10.2.0
-
getNotEmpty
Get the passed string but never return an empty string. If the passed parameter isnullor empty the second parameter is returned.- Parameters:
s- The parameter to be notnullnor empty.sDefaultIfEmpty- The value to be used if the first parameter isnullor empty. May benullbut in this case the call to this method is obsolete.- Returns:
- The passed default value if the string is
nullor empty, otherwise the input string.
-
getNotEmpty
@Nullable public static String getNotEmpty(@Nullable String s, @Nonnull Supplier<String> aDefaultIfEmpty) Get the passed string but never return an empty string. If the passed parameter isnullor empty the second parameter is returned.- Parameters:
s- The parameter to be notnullnor empty.aDefaultIfEmpty- The value supplier to be used if the first parameter isnullor empty. May not benull.- Returns:
- The passed default value if the string is
nullor empty, otherwise the input string. - Since:
- 10.2.0
-
getNotEmpty
@Nullable public static CharSequence getNotEmpty(@Nullable CharSequence s, @Nullable CharSequence sDefaultIfEmpty) Get the passed char sequence but never return an empty char sequence. If the passed parameter isnullor empty the second parameter is returned.- Parameters:
s- The parameter to be notnullnor empty.sDefaultIfEmpty- The value to be used if the first parameter isnullor empty. May benullbut in this case the call to this method is obsolete.- Returns:
- The passed default value if the char sequence is
nullor empty, otherwise the input char sequence.
-
getNotEmpty
@Nullable public static CharSequence getNotEmpty(@Nullable CharSequence s, @Nullable Supplier<? extends CharSequence> aDefaultIfEmpty) Get the passed char sequence but never return an empty char sequence. If the passed parameter isnullor empty the second parameter is returned.- Parameters:
s- The parameter to be notnullnor empty.aDefaultIfEmpty- The value supplier to be used if the first parameter isnullor empty. May not benull.- Returns:
- The passed default value if the char sequence is
nullor empty, otherwise the input char sequence. - Since:
- 10.2.0
-
getRepeated
Get the passed string element repeated for a certain number of times. Each string element is simply appended at the end of the string.- Parameters:
cElement- The character to get repeated.nRepeats- The number of repetitions to retrieve. May not be < 0.- Returns:
- A non-
nullstring containing the string element for the given number of times.
-
getRepeated
Get the passed string element repeated for a certain number of times. Each string element is simply appended at the end of the string.- Parameters:
sElement- The string to get repeated. May not benull.nRepeats- The number of repetitions to retrieve. May not be < 0.- Returns:
- A non-
nullstring containing the string element for the given number of times.
-
getWithLeading
@Nonnull public static String getWithLeading(@Nullable String sSrc, @Nonnegative int nMinLen, char cFront) Get a string that is filled at the beginning with the passed character until the minimum length is reached. If the input string is empty, the result is a string with the provided len only consisting of the passed characters. If the input String is longer than the provided length, it is returned unchanged.- Parameters:
sSrc- Source string. May benull.nMinLen- Minimum length. Should be > 0.cFront- The character to be used at the beginning- Returns:
- A non-
nullstring that has at least nLen chars
-
getWithLeading
Get a string that is filled at the beginning with the passed character until the minimum length is reached. If the input String is longer than the provided length, it is returned unchanged.- Parameters:
nValue- Source string. May benull.nMinLen- Minimum length. Should be > 0.cFront- The character to be used at the beginning- Returns:
- A non-
nullstring that has at least nLen chars - See Also:
-
getWithLeading
Get a string that is filled at the beginning with the passed character until the minimum length is reached. If the input String is longer than the provided length, it is returned unchanged.- Parameters:
nValue- Source string. May benull.nMinLen- Minimum length. Should be > 0.cFront- The character to be used at the beginning- Returns:
- A non-
nullstring that has at least nLen chars - See Also:
-
getWithTrailing
@Nonnull public static String getWithTrailing(@Nullable String sSrc, @Nonnegative int nMinLen, char cEnd) Get a string that is filled at the end with the passed character until the minimum length is reached. If the input string is empty, the result is a string with the provided len only consisting of the passed characters. If the input String is longer than the provided length, it is returned unchanged.- Parameters:
sSrc- Source string. May benull.nMinLen- Minimum length. Should be > 0.cEnd- The character to be used at the end- Returns:
- A non-
nullstring that has at least nLen chars
-
getLeadingZero
-
getLeadingZero
-
getLeadingZero
-
getLeadingZero
-
getLeadingZero
-
getLeadingZero
-
getLeadingZero
-
getReverse
-
getFirstChar
Get the first character of the passed character sequence- Parameters:
aCS- The source character sequence- Returns:
CGlobal.ILLEGAL_CHARif the passed sequence was empty
-
getFirstChar
public static char getFirstChar(@Nullable char[] aChars) Get the first character of the passed array- Parameters:
aChars- The character array- Returns:
CGlobal.ILLEGAL_CHARif the passed array was empty
-
getLastChar
Get the last character of the passed character sequence- Parameters:
aCS- The source character sequence- Returns:
CGlobal.ILLEGAL_CHARif the passed sequence was empty
-
getLastChar
public static char getLastChar(@Nullable char[] aChars) Get the last character of the passed array- Parameters:
aChars- The character array- Returns:
CGlobal.ILLEGAL_CHARif the passed array was empty
-
getIndexOf
Get the first index of sSearch within sText.- Parameters:
sText- The text to search in. May benull.sSearch- The text to search for. May benull.- Returns:
- The first index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOf
public static int getIndexOf(@Nullable String sText, @Nonnegative int nFromIndex, @Nullable String sSearch) Get the first index of sSearch within sText starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringsSearch- The text to search for. May benull.- Returns:
- The first index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOf
Get the last index of sSearch within sText.- Parameters:
sText- The text to search in. May benull.sSearch- The text to search for. May benull.- Returns:
- The last index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOf
public static int getLastIndexOf(@Nullable String sText, @Nonnegative int nFromIndex, @Nullable String sSearch) Get the last index of sSearch within sText starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringsSearch- The text to search for. May benull.- Returns:
- The last index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOf
Get the first index of cSearch within sText.- Parameters:
sText- The text to search in. May benull.cSearch- The character to search for. May benull.- Returns:
- The first index of sSearch within sText or -1 if cSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOf
Get the first index of cSearch within sText starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringcSearch- The character to search for. May benull.- Returns:
- The first index of sSearch within sText or -1 if cSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOf
Get the last index of cSearch within sText.- Parameters:
sText- The text to search in. May benull.cSearch- The character to search for. May benull.- Returns:
- The last index of sSearch within sText or -1 if cSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOf
Get the last index of cSearch within sText starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringcSearch- The character to search for. May benull.- Returns:
- The last index of sSearch within sText or -1 if cSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOfIgnoreCase
public static int getIndexOfIgnoreCase(@Nullable String sText, @Nullable String sSearch, @Nonnull Locale aSortLocale) Get the first index of sSearch within sText ignoring case.- Parameters:
sText- The text to search in. May benull.sSearch- The text to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The first index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOfIgnoreCase
public static int getIndexOfIgnoreCase(@Nullable String sText, @Nonnegative int nFromIndex, @Nullable String sSearch, @Nonnull Locale aSortLocale) Get the first index of sSearch within sText ignoring case starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringsSearch- The text to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The first index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOfIgnoreCase
public static int getLastIndexOfIgnoreCase(@Nullable String sText, @Nullable String sSearch, @Nonnull Locale aSortLocale) Get the last index of sSearch within sText ignoring case.- Parameters:
sText- The text to search in. May benull.sSearch- The text to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The last index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOfIgnoreCase
public static int getLastIndexOfIgnoreCase(@Nullable String sText, @Nonnegative int nFromIndex, @Nullable String sSearch, @Nonnull Locale aSortLocale) Get the last index of sSearch within sText ignoring case starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringsSearch- The text to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The last index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOfIgnoreCase
public static int getIndexOfIgnoreCase(@Nullable String sText, char cSearch, @Nonnull Locale aSortLocale) Get the first index of cSearch within sText ignoring case.- Parameters:
sText- The text to search in. May benull.cSearch- The char to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The first index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOfIgnoreCase
public static int getIndexOfIgnoreCase(@Nullable String sText, @Nonnegative int nFromIndex, char cSearch, @Nonnull Locale aSortLocale) Get the first index of cSearch within sText ignoring case starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringcSearch- The char to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The first index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOfIgnoreCase
public static int getLastIndexOfIgnoreCase(@Nullable String sText, char cSearch, @Nonnull Locale aSortLocale) Get the last index of cSearch within sText ignoring case.- Parameters:
sText- The text to search in. May benull.cSearch- The char to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The last index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOfIgnoreCase
public static int getLastIndexOfIgnoreCase(@Nullable String sText, @Nonnegative int nFromIndex, char cSearch, @Nonnull Locale aSortLocale) Get the last index of cSearch within sText ignoring case starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringcSearch- The char to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The last index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
contains
Check if sSearch is contained within sText.- Parameters:
sText- The text to search in. May benull.sSearch- The text to search for. May benull.- Returns:
trueif sSearch is contained in sText,falseotherwise.- See Also:
-
contains
Check if cSearch is contained within sText.- Parameters:
sText- The text to search in. May benull.cSearch- The character to search for. May benull.- Returns:
trueif cSearch is contained in sText,falseotherwise.- See Also:
-
containsIgnoreCase
public static boolean containsIgnoreCase(@Nullable String sText, @Nullable String sSearch, @Nonnull Locale aSortLocale) Check if sSearch is contained within sText ignoring case.- Parameters:
sText- The text to search in. May benull.sSearch- The text to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
trueif sSearch is contained in sText,falseotherwise.- See Also:
-
containsIgnoreCase
public static boolean containsIgnoreCase(@Nullable String sText, char cSearch, @Nonnull Locale aSortLocale) Check if cSearch is contained within sText ignoring case.- Parameters:
sText- The text to search in. May benull.cSearch- The char to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
trueif sSearch is contained in sText,falseotherwise.- See Also:
-
containsAny
public static boolean containsAny(@Nullable char[] aInput, @Nonnull char[] aSearchChars) Check if any of the passed searched characters is contained in the input char array.- Parameters:
aInput- The input char array. May benull.aSearchChars- The char array to search. May not benull.- Returns:
trueif at least any of the search char is contained in the input char array,falseotherwise.
-
containsAny
Check if any of the passed searched characters in contained in the input string.- Parameters:
sInput- The input string. May benull.aSearchChars- The char array to search. May not benull.- Returns:
trueif at least any of the search char is contained in the input char array,falseotherwise.
-
iterateChars
Iterate all characters and pass them to the provided consumer.- Parameters:
sInputString- Input String to use. May benullor empty.aConsumer- The consumer to be used. May not benull.
-
containsAny
Check if the passedCharSequencecontains any character matching the provided filter.- Parameters:
aCS- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is not empty.trueif the filter is notnulland at least one character of the string matches the filter.falseotherwise.- Since:
- 9.1.7
-
containsAny
Check if the passedStringcontains any character matching the provided filter.- Parameters:
sStr- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is not empty.trueif the filter is notnulland at least one character of the string matches the filter.falseotherwise.- Since:
- 9.1.7
-
containsNone
Check if the passedCharSequencecontains no character matching the provided filter.- Parameters:
aCS- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is empty.trueif the filter is notnulland no character of the string matches the filter.falseotherwise.- Since:
- 9.1.7
-
containsNone
Check if the passedStringcontains no character matching the provided filter.- Parameters:
sStr- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is empty.trueif the filter is notnulland no character of the string matches the filter.falseotherwise.- Since:
- 9.1.7
-
containsOnly
Check if the passedCharSequencecontains only characters matching the provided filter.- Parameters:
aCS- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is not empty.trueif the filter is notnulland the string has at least one character and all characters of the string match the filter.falseotherwise.- Since:
- 9.1.7
-
containsOnly
Check if the passedStringcontains only characters matching the provided filter.- Parameters:
sStr- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is not empty.trueif the filter is notnulland the string has at least one character and all characters of the string match the filter.falseotherwise.- Since:
- 9.1.7
-
isAllWhitespace
Check if the passed character sequence is only whitespace or not.- Parameters:
s- The character sequence to be checked. May benull.- Returns:
trueif the passed sequence is empty or if only whitespace characters are contained.- See Also:
-
startsWith
-
startsWithAny
-
startsWithIgnoreCase
-
startsWith
-
startsWith
-
startsWithIgnoreCase
-
endsWith
-
endsWithAny
-
endsWith
-
endsWith
-
endsWithIgnoreCase
-
endsWithIgnoreCase
-
iterateCodePoints
Iterate all code points and pass them to the provided consumer. This implementation is approximately 20% quicker thanCharSequence.codePoints().forEachOrdered(c)- Parameters:
sInputString- Input String to use. May benullor empty.aConsumer- The consumer to be used. May not benull.
-
explode
public static void explode(char cSep, @Nullable String sElements, @Nonnull Consumer<? super String> aConsumer) Split the provided string by the provided separator and invoke the consumer for each matched element. The number of returned items is unlimited.- Parameters:
cSep- The separator to use.sElements- The concatenated String to convert. May benullor empty.aConsumer- The non-nullconsumer that is invoked for each exploded element
-
explode
public static void explode(char cSep, @Nullable String sElements, int nMaxItems, @Nonnull Consumer<? super String> aConsumer) Split the provided string by the provided separator and invoke the consumer for each matched element. The maximum number of elements can be specified.- Parameters:
cSep- The separator to use.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.aConsumer- The non-nullconsumer that is invoked for each exploded element
-
explode
public static void explode(@Nonnull String sSep, @Nullable String sElements, @Nonnull Consumer<? super String> aConsumer) Split the provided string by the provided separator and invoke the consumer for each matched element.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.aConsumer- The non-nullconsumer that is invoked for each exploded element
-
explode
public static void explode(@Nonnull String sSep, @Nullable String sElements, int nMaxItems, @Nonnull Consumer<? super String> aConsumer) Split the provided string by the provided separator and invoke the consumer for each matched element. The maximum number of elements can be specified.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.aConsumer- The non-nullconsumer that is invoked for each exploded element
-
getExplodedArray
@Nonnull public static String[] getExplodedArray(char cSep, @Nullable String sElements, @CheckForSigned int nMaxItems) Take a concatenated String and return the passed String array of all elements in the passed string, using specified separator char.- Parameters:
cSep- The separator to use.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.- Returns:
- The passed collection and never
null.
-
getExplodedArray
Take a concatenated String and return the passed String array of all elements in the passed string, using specified separator char.- Parameters:
cSep- The separator to use.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The passed collection and never
null.
-
getExploded
@Nonnull @ReturnsMutableObject("The passed parameter") @CodingStyleguideUnaware public static <COLLTYPE extends Collection<String>> COLLTYPE getExploded(char cSep, @Nullable String sElements, int nMaxItems, @Nonnull COLLTYPE aCollection) Take a concatenated String and return the passed Collection of all elements in the passed string, using specified separator string.- Type Parameters:
COLLTYPE- The collection type to be passed and returned- Parameters:
cSep- The separator to use.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.aCollection- The non-nulltarget collection that should be filled with the exploded elements- Returns:
- The passed collection and never
null.
-
getExploded
@Nonnull @ReturnsMutableCopy public static List<String> getExploded(char cSep, @Nullable String sElements) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.- Parameters:
cSep- The separator character to use.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The
Listrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getExploded
@Nonnull @ReturnsMutableCopy public static List<String> getExploded(char cSep, @Nullable String sElements, int nMaxItems) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.- Parameters:
cSep- The separator character to use.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.- Returns:
- The
Listrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getExploded
@Nonnull @CodingStyleguideUnaware public static <COLLTYPE extends Collection<String>> COLLTYPE getExploded(@Nonnull String sSep, @Nullable String sElements, int nMaxItems, @Nonnull COLLTYPE aCollection) Take a concatenated String and return the passed Collection of all elements in the passed string, using specified separator string.- Type Parameters:
COLLTYPE- The collection type to be used and returned- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.aCollection- The non-nulltarget collection that should be filled with the exploded elements- Returns:
- The passed collection and never
null.
-
getExploded
@Nonnull @ReturnsMutableCopy public static List<String> getExploded(@Nonnull String sSep, @Nullable String sElements) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The
Listrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getExploded
@Nonnull @ReturnsMutableCopy public static List<String> getExploded(@Nonnull String sSep, @Nullable String sElements, int nMaxItems) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.- Returns:
- The
Listrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getExplodedToSet
@Nonnull @ReturnsMutableCopy public static HashSet<String> getExplodedToSet(@Nonnull String sSep, @Nullable String sElements) Take a concatenated String and return aSetof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The
Setrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getExplodedToOrderedSet
@Nonnull @ReturnsMutableCopy public static LinkedHashSet<String> getExplodedToOrderedSet(@Nonnull String sSep, @Nullable String sElements) Take a concatenated String and return an orderedLinkedHashSetof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The ordered
Setrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getExplodedToSortedSet
@Nonnull @ReturnsMutableCopy public static TreeSet<String> getExplodedToSortedSet(@Nonnull String sSep, @Nullable String sElements) Take a concatenated String and return a sortedTreeSetof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The sorted
Setrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getConcatenatedOnDemand
@Nonnull public static String getConcatenatedOnDemand(@Nullable String sFront, @Nullable String sEnd) Concatenate the strings sFront and sEnd. If either front or back isnullor empty only the other element is returned. If both strings arenullor empty and empty String is returned.- Parameters:
sFront- Front string. May benull.sEnd- May benull.- Returns:
- The concatenated string. Never
null.
-
getConcatenatedOnDemand
@Nonnull public static String getConcatenatedOnDemand(@Nullable String sFront, @Nullable String sSep, @Nullable String sEnd) Concatenate the strings sFront and sEnd by the "sSep" string. If either front or back isnullor empty, the separator is not applied.- Parameters:
sFront- Front string. May benull.sSep- Separator string. May benull.sEnd- May benull.- Returns:
- The concatenated string.
-
getConcatenatedOnDemand
@Nonnull public static String getConcatenatedOnDemand(@Nullable String sFront, char cSep, @Nullable String sEnd) Concatenate the strings sFront and sEnd by the "cSep" separator. If either front or back isnullor empty, the separator is not applied.- Parameters:
sFront- Front string. May benull.cSep- Separator character.sEnd- May benull.- Returns:
- The concatenated string.
-
getQuoted
Get the provided string quoted or unquoted if it isnull.- Parameters:
sSource- Source string. May benull.- Returns:
- The String
"null"if the source isnull,"'" + sSource + "'"otherwise. - Since:
- 9.2.0
-
appendQuoted
Append the provided string quoted or unquoted if it isnull.- Parameters:
aTarget- The target to write to. May not benull.sSource- Source string. May benull.- Since:
- 9.2.0
- See Also:
-
appendQuoted
public static void appendQuoted(@Nonnull Appendable aTarget, @Nullable String sSource) throws IOException Append the provided string quoted or unquoted if it isnull.- Parameters:
aTarget- The target to write to. May not benull.sSource- Source string. May benull.- Throws:
IOException- in case of IO error- Since:
- 9.2.0
- See Also:
-
trimLeadingWhitespaces
Remove any leading whitespaces from the passed string.- Parameters:
s- the String to be trimmed- Returns:
- the original String with all leading whitespaces removed
-
trimTrailingWhitespaces
Remove any trailing whitespaces from the passed string.- Parameters:
s- the String to be cut- Returns:
- the original String with all trailing whitespaces removed
-
trimStart
@Nullable @CheckReturnValue public static String trimStart(@Nullable String sSrc, @Nullable String sLead) Trim the passed lead from the source value. If the source value does not start with the passed lead, nothing happens.- Parameters:
sSrc- The input source stringsLead- The string to be trimmed of the beginning- Returns:
- The trimmed string, or the original input string, if the lead was not found
- See Also:
-
trimStartRepeatedly
-
trimStart
Trim the passed lead from the source value. If the source value does not start with the passed lead, nothing happens.- Parameters:
sSrc- The input source stringcLead- The char to be trimmed of the beginning- Returns:
- The trimmed string, or the original input string, if the lead was not found
- See Also:
-
trimStartRepeatedly
-
trimStart
@Nullable @CheckReturnValue public static String trimStart(@Nullable String sSrc, @Nonnegative int nCount) Trim the passed lead from the source value. If the source value does not start with the passed lead, nothing happens.- Parameters:
sSrc- The input source stringnCount- The number of characters to trim at the end.- Returns:
- The trimmed string, or an empty string if nCount is ≥ the length of the source string
-
trimEnd
@Nullable @CheckReturnValue public static String trimEnd(@Nullable String sSrc, @Nullable String sTail) Trim the passed tail from the source value. If the source value does not end with the passed tail, nothing happens.- Parameters:
sSrc- The input source stringsTail- The string to be trimmed of the end- Returns:
- The trimmed string, or the original input string, if the tail was not found
- See Also:
-
trimEndRepeatedly
-
trimEnd
Trim the passed tail from the source value. If the source value does not end with the passed tail, nothing happens.- Parameters:
sSrc- The input source stringcTail- The char to be trimmed of the end- Returns:
- The trimmed string, or the original input string, if the tail was not found
- See Also:
-
trimEndRepeatedly
-
trimEnd
@Nullable @CheckReturnValue public static String trimEnd(@Nullable String sSrc, @Nonnegative int nCount) Trim the passed tail from the source value. If the source value does not end with the passed tail, nothing happens.- Parameters:
sSrc- The input source stringnCount- The number of characters to trim at the end.- Returns:
- The trimmed string, or an empty string if nCount is ≥ the length of the source string
-
trimStartAndEnd
@Nullable @CheckReturnValue public static String trimStartAndEnd(@Nullable String sSrc, @Nullable String sValueToTrim) Trim the passed lead and tail from the source value. If the source value does not start with the passed trimmed value, nothing happens.- Parameters:
sSrc- The input source stringsValueToTrim- The string to be trimmed of the beginning and the end- Returns:
- The trimmed string, or the original input string, if the value to trim was not found
- See Also:
-
trimStartAndEnd
@Nullable @CheckReturnValue public static String trimStartAndEnd(@Nullable String sSrc, @Nullable String sLead, @Nullable String sTail) Trim the passed lead and tail from the source value. If the source value does not start with the passed lead and does not end with the passed tail, nothing happens.- Parameters:
sSrc- The input source stringsLead- The string to be trimmed of the beginningsTail- The string to be trimmed of the end- Returns:
- The trimmed string, or the original input string, if the lead and the tail were not found
- See Also:
-
trimStartAndEnd
@Nullable @CheckReturnValue public static String trimStartAndEnd(@Nullable String sSrc, char cValueToTrim) Trim the passed lead and tail from the source value. If the source value does not start with the passed trimmed value, nothing happens.- Parameters:
sSrc- The input source stringcValueToTrim- The char to be trimmed of the beginning and the end- Returns:
- The trimmed string, or the original input string, if the value to trim was not found
- See Also:
-
trimStartAndEnd
@Nullable @CheckReturnValue public static String trimStartAndEnd(@Nullable String sSrc, char cLead, char cTail) Trim the passed lead and tail from the source value. If the source value does not start with the passed lead and does not end with the passed tail, nothing happens.- Parameters:
sSrc- The input source stringcLead- The char to be trimmed of the beginningcTail- The char to be trimmed of the end- Returns:
- The trimmed string, or the original input string, if the lead and the tail were not found
- See Also:
-
trim
Trim the passed string, if it is notnull.- Parameters:
s- The string to be trimmed. May benull.- Returns:
nullif the input string wasnull, the non-nulltrimmed string otherwise.- See Also:
-
getCutAfterLength
-
getCutAfterLength
-
getToString
Convert the passed object to a string using theObject.toString()method.- Parameters:
aObject- The value to be converted. May benull.- Returns:
- An empty string in case the passed object was
null. Nevernull. - See Also:
-
getToString
Convert the passed object to a string using theObject.toString()method or otherwise return the passed default value.- Parameters:
aObject- The value to be converted. May benull.sNullValue- The value to be returned in case the passed object isnull. May benullitself.- Returns:
- The passed default value in case the passed object was
nullor the result ofObject.toString()on the passed object. - See Also:
-
getWithoutLeadingChar
Get the passed string without the first char.- Parameters:
sStr- The source string. May benull.- Returns:
- An empty, non-
nullstring if the passed string has a length ≤ 1.
-
getWithoutLeadingChars
@Nonnull public static String getWithoutLeadingChars(@Nullable String sStr, @Nonnegative int nCount) Get the passed string without the specified number of leading chars.- Parameters:
sStr- The source string. May benull.nCount- The number of chars to remove.- Returns:
- An empty, non-
nullstring if the passed string has a length ≤nCount.
-
getWithoutTrailingChar
Get the passed string without the last char.- Parameters:
sStr- The source string. May benull.- Returns:
- An empty, non-
nullstring if the passed string has a length ≤ 1.
-
getWithoutTrailingChars
@Nonnull public static String getWithoutTrailingChars(@Nullable String sStr, @Nonnegative int nCount) Get the passed string without the specified number of trailing chars.- Parameters:
sStr- The source string. May benull.nCount- The number of chars to remove.- Returns:
- An empty, non-
nullstring if the passed string has a length ≤nCount.
-
getWithoutAnySpaces
Get the passed string where all spaces (white spaces or unicode spaces) have been removed.- Parameters:
sStr- The source string. May benull- Returns:
- A non-
nullstring representing the passed string without any spaces
-
getUntilFirstIncl
Get everything from the string up to and including the first passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getUntilFirstExcl
Get everything from the string up to and excluding first the passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getUntilFirstIncl
Get everything from the string up to and including the first passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the empty string is returned.
-
getUntilFirstExcl
Get everything from the string up to and excluding the first passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the empty string is returned.
-
getUntilLastIncl
Get everything from the string up to and including the first passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getUntilLastExcl
Get everything from the string up to and excluding first the passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getUntilLastIncl
Get everything from the string up to and including the first passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the empty string is returned.
-
getUntilLastExcl
Get everything from the string up to and excluding the first passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the empty string is returned.
-
getFromFirstIncl
Get everything from the string from and including the first passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getFromFirstExcl
Get everything from the string from and excluding the first passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getFromFirstIncl
Get everything from the string from and including the passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
-
getFromFirstExcl
Get everything from the string from and excluding the passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
-
getFromLastIncl
Get everything from the string from and including the first passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getFromLastExcl
Get everything from the string from and excluding the first passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getFromLastIncl
Get everything from the string from and including the passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
-
getFromLastExcl
Get everything from the string from and excluding the passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
-
getFirstToken
Get the first token up to (and excluding) the separating character.- Parameters:
sStr- The string to search. May benull.cSearch- The search character.- Returns:
- The passed string if no such separator token was found.
-
getFirstToken
Get the first token up to (and excluding) the separating string.- Parameters:
sStr- The string to search. May benull.sSearch- The search string. May benull.- Returns:
- The passed string if no such separator token was found.
-
getLastToken
Get the last token from (and excluding) the separating character.- Parameters:
sStr- The string to search. May benull.cSearch- The search character.- Returns:
- The passed string if no such separator token was found.
-
getLastToken
Get the last token from (and excluding) the separating string.- Parameters:
sStr- The string to search. May benull.sSearch- The search string. May benull.- Returns:
- The passed string if no such separator token was found.
-
isEmpty(CharSequence)instead