Class StringHelper

java.lang.Object
com.helger.base.string.StringHelper

@Immutable public class StringHelper extends Object
Simple string utility methods, originally in StringHelper.
Since:
v12.0.0
Author:
Philip Helger
  • Constructor Details

    • StringHelper

      protected StringHelper()
  • Method Details

    • isEmpty

      public static boolean isEmpty(@Nullable CharSequence aCS)
      Check if the string is null or empty.
      Parameters:
      aCS - The character sequence to check. May be null.
      Returns:
      true if the string is null or empty, false otherwise
      Since:
      10.1.8
    • isEmpty

      public static boolean isEmpty(@Nullable String sStr)
      Check if the string is null or empty.
      Parameters:
      sStr - The string to check. May be null.
      Returns:
      true if the string is null or empty, false otherwise
      Since:
      10.1.8
    • isEmptyAfterTrim

      public static boolean isEmptyAfterTrim(@Nullable String s)
      Check if the string is null or empty after trimming.
      Parameters:
      s - The string to check. May be null.
      Returns:
      true if the string is null or empty or consists only of whitespaces, false otherwise
      Since:
      10.1.8
    • isNotEmpty

      public static boolean isNotEmpty(@Nullable CharSequence aCS)
      Check if the string contains any char.
      Parameters:
      aCS - The character sequence to check. May be null.
      Returns:
      true if the string contains at least one, false otherwise
      Since:
      10.1.8
    • isNotEmpty

      public static boolean isNotEmpty(@Nullable String sStr)
      Check if the string contains any char.
      Parameters:
      sStr - The string to check. May be null.
      Returns:
      true if the string contains at least one char, false otherwise
      Since:
      10.1.8
    • isNotEmptyAfterTrim

      public static boolean isNotEmptyAfterTrim(@Nullable String s)
      Check if the string neither null nor empty after trimming.
      Parameters:
      s - The string to check. May be null.
      Returns:
      true if the string is neither null nor empty nor consists only of whitespaces, false otherwise
      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.
      Check if the string is null or empty.
      Parameters:
      aCS - The character sequence to check. May be null.
      Returns:
      true if the string is null or empty, false otherwise
    • hasNoText

      @Deprecated(forRemoval=true, since="12.0.0") public static boolean hasNoText(@Nullable String sStr)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use isEmpty(String) instead
      Check if the string is null or empty.
      Parameters:
      sStr - The string to check. May be null.
      Returns:
      true if the string is null or empty, false otherwise
    • 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.
      Check if the string contains any char.
      Parameters:
      aCS - The character sequence to check. May be null.
      Returns:
      true if the string contains at least one, false otherwise
    • hasText

      @Deprecated(forRemoval=true, since="12.0.0") public static boolean hasText(@Nullable String sStr)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use isNotEmpty(String) instead
      Check if the string contains any char.
      Parameters:
      sStr - The string to check. May be null.
      Returns:
      true if the string contains at least one char, false otherwise
    • 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.
      Check if the string neither null nor empty after trimming.
      Parameters:
      s - The string to check. May be null.
      Returns:
      true if the string is neither null nor empty nor consists only of whitespaces, false otherwise
    • getLength

      @Nonnegative public static int getLength(@Nullable CharSequence aCS)
      Get the length of the passed character sequence.
      Parameters:
      aCS - The character sequence who's length is to be determined. May be null.
      Returns:
      0 if the parameter is null, its length otherwise.
      See Also:
    • getNotNull

      @Nonnull public static String getNotNull(@Nullable String s)
      Get the passed string but never return null. If the passed parameter is null an empty string is returned.
      Parameters:
      s - The parameter to be not null.
      Returns:
      An empty string if the passed parameter is null, the passed string otherwise.
    • getNotNull

      @Nullable public static String getNotNull(@Nullable String s, @Nullable String sDefaultIfNull)
      Get the passed string but never return null. If the passed parameter is null the second parameter is returned.
      Parameters:
      s - The parameter to be not null.
      sDefaultIfNull - The value to be used if the first parameter is null. May be null but 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 return null. If the passed parameter is null the second parameter is returned.
      Parameters:
      s - The parameter to be not null.
      aDefaultIfNull - The value supplier to be used if the first parameter is null. May not be null.
      Returns:
      The passed default value if the string is null, otherwise the input string.
      Since:
      10.2.0
    • getNotNull

      @Nonnull public static CharSequence getNotNull(@Nullable CharSequence s)
      Get the passed CharSequence but never return null. If the passed parameter is null an empty string is returned.
      Parameters:
      s - The parameter to be not null.
      Returns:
      An empty string if the passed parameter is null, the passed CharSequence otherwise.
    • getNotNull

      @Nullable public static CharSequence getNotNull(@Nullable CharSequence s, @Nullable CharSequence sDefaultIfNull)
      Get the passed CharSequence but never return null. If the passed parameter is null the second parameter is returned.
      Parameters:
      s - The parameter to be not null.
      sDefaultIfNull - The value to be used if the first parameter is null. May be null but in this case the call to this method is obsolete.
      Returns:
      The passed default value if the string is null, otherwise the input CharSequence.
    • getNotNull

      @Nullable public static CharSequence getNotNull(@Nullable CharSequence s, @Nonnull Supplier<? extends CharSequence> aDefaultIfNull)
      Get the passed CharSequence but never return null. If the passed parameter is null the second parameter is returned.
      Parameters:
      s - The parameter to be not null.
      aDefaultIfNull - The value supplier to be used if the first parameter is null. May not be null.
      Returns:
      The passed default value if the string is null, otherwise the input CharSequence.
      Since:
      10.2.0
    • getNotEmpty

      @Nullable public static String getNotEmpty(@Nullable String s, @Nullable String sDefaultIfEmpty)
      Get the passed string but never return an empty string. If the passed parameter is null or empty the second parameter is returned.
      Parameters:
      s - The parameter to be not null nor empty.
      sDefaultIfEmpty - The value to be used if the first parameter is null or empty. May be null but in this case the call to this method is obsolete.
      Returns:
      The passed default value if the string is null or 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 is null or empty the second parameter is returned.
      Parameters:
      s - The parameter to be not null nor empty.
      aDefaultIfEmpty - The value supplier to be used if the first parameter is null or empty. May not be null.
      Returns:
      The passed default value if the string is null or 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 is null or empty the second parameter is returned.
      Parameters:
      s - The parameter to be not null nor empty.
      sDefaultIfEmpty - The value to be used if the first parameter is null or empty. May be null but in this case the call to this method is obsolete.
      Returns:
      The passed default value if the char sequence is null or 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 is null or empty the second parameter is returned.
      Parameters:
      s - The parameter to be not null nor empty.
      aDefaultIfEmpty - The value supplier to be used if the first parameter is null or empty. May not be null.
      Returns:
      The passed default value if the char sequence is null or empty, otherwise the input char sequence.
      Since:
      10.2.0
    • getRepeated

      @Nonnull public static String getRepeated(char cElement, @Nonnegative int nRepeats)
      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-null string containing the string element for the given number of times.
    • getRepeated

      @Nonnull public static String getRepeated(@Nonnull String sElement, @Nonnegative int nRepeats)
      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 be null.
      nRepeats - The number of repetitions to retrieve. May not be < 0.
      Returns:
      A non-null string 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 be null.
      nMinLen - Minimum length. Should be > 0.
      cFront - The character to be used at the beginning
      Returns:
      A non-null string that has at least nLen chars
    • getWithLeading

      @Nonnull public static String getWithLeading(int nValue, @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 longer than the provided length, it is returned unchanged.
      Parameters:
      nValue - Source string. May be null.
      nMinLen - Minimum length. Should be > 0.
      cFront - The character to be used at the beginning
      Returns:
      A non-null string that has at least nLen chars
      See Also:
    • getWithLeading

      @Nonnull public static String getWithLeading(long nValue, @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 longer than the provided length, it is returned unchanged.
      Parameters:
      nValue - Source string. May be null.
      nMinLen - Minimum length. Should be > 0.
      cFront - The character to be used at the beginning
      Returns:
      A non-null string 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 be null.
      nMinLen - Minimum length. Should be > 0.
      cEnd - The character to be used at the end
      Returns:
      A non-null string that has at least nLen chars
    • getLeadingZero

      @Nullable public static String getLeadingZero(@Nullable Byte aValue, int nChars)
    • getLeadingZero

      @Nullable public static String getLeadingZero(@Nullable Integer aValue, int nChars)
    • getLeadingZero

      @Nullable public static String getLeadingZero(@Nullable Long aValue, int nChars)
    • getLeadingZero

      @Nullable public static String getLeadingZero(@Nullable Short aValue, int nChars)
    • getLeadingZero

      @Nonnull public static String getLeadingZero(int nValue, int nChars)
    • getLeadingZero

      @Nonnull public static String getLeadingZero(long nValue, int nChars)
    • getLeadingZero

      @Nonnull public static String getLeadingZero(@Nonnull String sValue, int nChars)
    • getReverse

      @Nullable public static String getReverse(@Nullable String sStr)
    • getFirstChar

      public static char getFirstChar(@Nullable CharSequence aCS)
      Get the first character of the passed character sequence
      Parameters:
      aCS - The source character sequence
      Returns:
      CGlobal.ILLEGAL_CHAR if 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_CHAR if the passed array was empty
    • getLastChar

      public static char getLastChar(@Nullable CharSequence aCS)
      Get the last character of the passed character sequence
      Parameters:
      aCS - The source character sequence
      Returns:
      CGlobal.ILLEGAL_CHAR if 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_CHAR if the passed array was empty
    • getIndexOf

      public static int getIndexOf(@Nullable String sText, @Nullable String sSearch)
      Get the first index of sSearch within sText.
      Parameters:
      sText - The text to search in. May be null.
      sSearch - The text to search for. May be null.
      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 be null.
      nFromIndex - The index to start searching in the source string
      sSearch - The text to search for. May be null.
      Returns:
      The first 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, @Nullable String sSearch)
      Get the last index of sSearch within sText.
      Parameters:
      sText - The text to search in. May be null.
      sSearch - The text to search for. May be null.
      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 be null.
      nFromIndex - The index to start searching in the source string
      sSearch - The text to search for. May be null.
      Returns:
      The last 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, char cSearch)
      Get the first index of cSearch within sText.
      Parameters:
      sText - The text to search in. May be null.
      cSearch - The character to search for. May be null.
      Returns:
      The first index of sSearch within sText or -1 if cSearch was not found or if any parameter was null.
      See Also:
    • getIndexOf

      public static int getIndexOf(@Nullable String sText, @Nonnegative int nFromIndex, char cSearch)
      Get the first index of cSearch within sText starting at index nFromIndex.
      Parameters:
      sText - The text to search in. May be null.
      nFromIndex - The index to start searching in the source string
      cSearch - The character to search for. May be null.
      Returns:
      The first index of sSearch within sText or -1 if cSearch was not found or if any parameter was null.
      See Also:
    • getLastIndexOf

      public static int getLastIndexOf(@Nullable String sText, char cSearch)
      Get the last index of cSearch within sText.
      Parameters:
      sText - The text to search in. May be null.
      cSearch - The character to search for. May be null.
      Returns:
      The last index of sSearch within sText or -1 if cSearch was not found or if any parameter was null.
      See Also:
    • getLastIndexOf

      public static int getLastIndexOf(@Nullable String sText, @Nonnegative int nFromIndex, char cSearch)
      Get the last index of cSearch within sText starting at index nFromIndex.
      Parameters:
      sText - The text to search in. May be null.
      nFromIndex - The index to start searching in the source string
      cSearch - The character to search for. May be null.
      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 be null.
      sSearch - The text to search for. May be null.
      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 be null.
      nFromIndex - The index to start searching in the source string
      sSearch - The text to search for. May be null.
      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 be null.
      sSearch - The text to search for. May be null.
      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 be null.
      nFromIndex - The index to start searching in the source string
      sSearch - The text to search for. May be null.
      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 be null.
      cSearch - The char to search for. May be null.
      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 be null.
      nFromIndex - The index to start searching in the source string
      cSearch - The char to search for. May be null.
      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 be null.
      cSearch - The char to search for. May be null.
      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 be null.
      nFromIndex - The index to start searching in the source string
      cSearch - The char to search for. May be null.
      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

      public static boolean contains(@Nullable String sText, @Nullable String sSearch)
      Check if sSearch is contained within sText.
      Parameters:
      sText - The text to search in. May be null.
      sSearch - The text to search for. May be null.
      Returns:
      true if sSearch is contained in sText, false otherwise.
      See Also:
    • contains

      public static boolean contains(@Nullable String sText, char cSearch)
      Check if cSearch is contained within sText.
      Parameters:
      sText - The text to search in. May be null.
      cSearch - The character to search for. May be null.
      Returns:
      true if cSearch is contained in sText, false otherwise.
      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 be null.
      sSearch - The text to search for. May be null.
      aSortLocale - The locale to be used for case unifying.
      Returns:
      true if sSearch is contained in sText, false otherwise.
      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 be null.
      cSearch - The char to search for. May be null.
      aSortLocale - The locale to be used for case unifying.
      Returns:
      true if sSearch is contained in sText, false otherwise.
      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 be null.
      aSearchChars - The char array to search. May not be null.
      Returns:
      true if at least any of the search char is contained in the input char array, false otherwise.
    • containsAny

      public static boolean containsAny(@Nullable String sInput, @Nonnull char[] aSearchChars)
      Check if any of the passed searched characters in contained in the input string.
      Parameters:
      sInput - The input string. May be null.
      aSearchChars - The char array to search. May not be null.
      Returns:
      true if at least any of the search char is contained in the input char array, false otherwise.
    • iterateChars

      public static void iterateChars(@Nullable String sInputString, @Nonnull ICharConsumer aConsumer)
      Iterate all characters and pass them to the provided consumer.
      Parameters:
      sInputString - Input String to use. May be null or empty.
      aConsumer - The consumer to be used. May not be null.
    • containsAny

      public static boolean containsAny(@Nullable CharSequence aCS, @Nullable ICharPredicate aFilter)
      Check if the passed CharSequence contains any character matching the provided filter.
      Parameters:
      aCS - String to check. May be null.
      aFilter - The filter to use. May be null.
      Returns:
      true if the filter is null and the string is not empty. true if the filter is not null and at least one character of the string matches the filter. false otherwise.
      Since:
      9.1.7
    • containsAny

      public static boolean containsAny(@Nullable String sStr, @Nullable ICharPredicate aFilter)
      Check if the passed String contains any character matching the provided filter.
      Parameters:
      sStr - String to check. May be null.
      aFilter - The filter to use. May be null.
      Returns:
      true if the filter is null and the string is not empty. true if the filter is not null and at least one character of the string matches the filter. false otherwise.
      Since:
      9.1.7
    • containsNone

      public static boolean containsNone(@Nullable CharSequence aCS, @Nullable ICharPredicate aFilter)
      Check if the passed CharSequence contains no character matching the provided filter.
      Parameters:
      aCS - String to check. May be null.
      aFilter - The filter to use. May be null.
      Returns:
      true if the filter is null and the string is empty. true if the filter is not null and no character of the string matches the filter. false otherwise.
      Since:
      9.1.7
    • containsNone

      public static boolean containsNone(@Nullable String sStr, @Nullable ICharPredicate aFilter)
      Check if the passed String contains no character matching the provided filter.
      Parameters:
      sStr - String to check. May be null.
      aFilter - The filter to use. May be null.
      Returns:
      true if the filter is null and the string is empty. true if the filter is not null and no character of the string matches the filter. false otherwise.
      Since:
      9.1.7
    • containsOnly

      public static boolean containsOnly(@Nullable CharSequence aCS, @Nullable ICharPredicate aFilter)
      Check if the passed CharSequence contains only characters matching the provided filter.
      Parameters:
      aCS - String to check. May be null.
      aFilter - The filter to use. May be null.
      Returns:
      true if the filter is null and the string is not empty. true if the filter is not null and the string has at least one character and all characters of the string match the filter. false otherwise.
      Since:
      9.1.7
    • containsOnly

      public static boolean containsOnly(@Nullable String sStr, @Nullable ICharPredicate aFilter)
      Check if the passed String contains only characters matching the provided filter.
      Parameters:
      sStr - String to check. May be null.
      aFilter - The filter to use. May be null.
      Returns:
      true if the filter is null and the string is not empty. true if the filter is not null and the string has at least one character and all characters of the string match the filter. false otherwise.
      Since:
      9.1.7
    • isAllWhitespace

      public static boolean isAllWhitespace(@Nullable CharSequence s)
      Check if the passed character sequence is only whitespace or not.
      Parameters:
      s - The character sequence to be checked. May be null.
      Returns:
      true if the passed sequence is empty or if only whitespace characters are contained.
      See Also:
    • startsWith

      public static boolean startsWith(@Nullable CharSequence aCS, char c)
    • startsWithAny

      public static boolean startsWithAny(@Nullable CharSequence aCS, @Nullable char[] aChars)
    • startsWithIgnoreCase

      public static boolean startsWithIgnoreCase(@Nullable CharSequence aCS, char c)
    • startsWith

      public static boolean startsWith(@Nullable CharSequence aCS, @Nullable CharSequence aSearch)
    • startsWith

      public static boolean startsWith(@Nullable String sStr, @Nullable String sSearch)
    • startsWithIgnoreCase

      public static boolean startsWithIgnoreCase(@Nullable String sStr, @Nullable String sSearch)
    • endsWith

      public static boolean endsWith(@Nullable CharSequence aCS, char c)
    • endsWithAny

      public static boolean endsWithAny(@Nullable CharSequence aCS, @Nullable char[] aChars)
    • endsWith

      public static boolean endsWith(@Nullable CharSequence aCS, @Nullable CharSequence aSearch)
    • endsWith

      public static boolean endsWith(@Nullable String sStr, @Nullable String sSearch)
    • endsWithIgnoreCase

      public static boolean endsWithIgnoreCase(@Nullable CharSequence aCS, char c)
    • endsWithIgnoreCase

      public static boolean endsWithIgnoreCase(@Nullable String sStr, @Nullable String sSearch)
    • iterateCodePoints

      public static void iterateCodePoints(@Nullable String sInputString, @Nonnull IntConsumer aConsumer)
      Iterate all code points and pass them to the provided consumer. This implementation is approximately 20% quicker than CharSequence.codePoints().forEachOrdered(c)
      Parameters:
      sInputString - Input String to use. May be null or empty.
      aConsumer - The consumer to be used. May not be null.
    • 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 be null or empty.
      aConsumer - The non-null consumer 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 be null or 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-null consumer 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 be null.
      sElements - The concatenated String to convert. May be null or empty.
      aConsumer - The non-null consumer 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 be null.
      sElements - The concatenated String to convert. May be null or 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-null consumer 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 be null or 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

      @Nonnull public static String[] getExplodedArray(char cSep, @Nullable String sElements)
      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 be null or 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 be null or 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-null target 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 a List of all elements in the passed string, using specified separator string.
      Parameters:
      cSep - The separator character to use.
      sElements - The concatenated String to convert. May be null or empty.
      Returns:
      The List represented by the passed string. Never null. If the passed input string is null or "" 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 a List of all elements in the passed string, using specified separator string.
      Parameters:
      cSep - The separator character to use.
      sElements - The concatenated String to convert. May be null or 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 List represented by the passed string. Never null. If the passed input string is null or "" 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 be null.
      sElements - The concatenated String to convert. May be null or 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-null target 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 a List of all elements in the passed string, using specified separator string.
      Parameters:
      sSep - The separator to use. May not be null.
      sElements - The concatenated String to convert. May be null or empty.
      Returns:
      The List represented by the passed string. Never null. If the passed input string is null or "" 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 a List of all elements in the passed string, using specified separator string.
      Parameters:
      sSep - The separator to use. May not be null.
      sElements - The concatenated String to convert. May be null or 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 List represented by the passed string. Never null. If the passed input string is null or "" 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 a Set of all elements in the passed string, using specified separator string.
      Parameters:
      sSep - The separator to use. May not be null.
      sElements - The concatenated String to convert. May be null or empty.
      Returns:
      The Set represented by the passed string. Never null. If the passed input string is null or "" 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 ordered LinkedHashSet of all elements in the passed string, using specified separator string.
      Parameters:
      sSep - The separator to use. May not be null.
      sElements - The concatenated String to convert. May be null or empty.
      Returns:
      The ordered Set represented by the passed string. Never null. If the passed input string is null or "" 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 sorted TreeSet of all elements in the passed string, using specified separator string.
      Parameters:
      sSep - The separator to use. May not be null.
      sElements - The concatenated String to convert. May be null or empty.
      Returns:
      The sorted Set represented by the passed string. Never null. If the passed input string is null or "" 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 is null or empty only the other element is returned. If both strings are null or empty and empty String is returned.
      Parameters:
      sFront - Front string. May be null.
      sEnd - May be null.
      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 is null or empty, the separator is not applied.
      Parameters:
      sFront - Front string. May be null.
      sSep - Separator string. May be null.
      sEnd - May be null.
      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 is null or empty, the separator is not applied.
      Parameters:
      sFront - Front string. May be null.
      cSep - Separator character.
      sEnd - May be null.
      Returns:
      The concatenated string.
    • getQuoted

      @Nonnull public static String getQuoted(@Nullable String sSource)
      Get the provided string quoted or unquoted if it is null.
      Parameters:
      sSource - Source string. May be null.
      Returns:
      The String "null" if the source is null, "'" + sSource + "'" otherwise.
      Since:
      9.2.0
    • appendQuoted

      public static void appendQuoted(@Nonnull StringBuilder aTarget, @Nullable String sSource)
      Append the provided string quoted or unquoted if it is null.
      Parameters:
      aTarget - The target to write to. May not be null.
      sSource - Source string. May be null.
      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 is null.
      Parameters:
      aTarget - The target to write to. May not be null.
      sSource - Source string. May be null.
      Throws:
      IOException - in case of IO error
      Since:
      9.2.0
      See Also:
    • trimLeadingWhitespaces

      @Nullable @CheckReturnValue public static String trimLeadingWhitespaces(@Nullable String s)
      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

      @Nullable @CheckReturnValue public static String trimTrailingWhitespaces(@Nullable String s)
      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 string
      sLead - 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

      @Nullable @CheckReturnValue public static String trimStartRepeatedly(@Nullable String sSrc, @Nullable String sLead)
    • trimStart

      @Nullable @CheckReturnValue public static String trimStart(@Nullable String sSrc, char cLead)
      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 string
      cLead - 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

      @Nullable @CheckReturnValue public static String trimStartRepeatedly(@Nullable String sSrc, char cLead)
    • 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 string
      nCount - 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 string
      sTail - 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

      @Nullable @CheckReturnValue public static String trimEndRepeatedly(@Nullable String sSrc, @Nullable String sTail)
    • trimEnd

      @Nullable @CheckReturnValue public static String trimEnd(@Nullable String sSrc, char cTail)
      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 string
      cTail - 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

      @Nullable @CheckReturnValue public static String trimEndRepeatedly(@Nullable String sSrc, char cTail)
    • 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 string
      nCount - 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 string
      sValueToTrim - 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 string
      sLead - The string to be trimmed of the beginning
      sTail - 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 string
      cValueToTrim - 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 string
      cLead - The char to be trimmed of the beginning
      cTail - 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

      @Nullable @CheckReturnValue public static String trim(@Nullable String s)
      Trim the passed string, if it is not null.
      Parameters:
      s - The string to be trimmed. May be null.
      Returns:
      null if the input string was null, the non-null trimmed string otherwise.
      See Also:
    • getCutAfterLength

      @Nonnull public static String getCutAfterLength(@Nonnull String sValue, @Nonnegative int nMaxLength)
    • getCutAfterLength

      @Nonnull public static String getCutAfterLength(@Nonnull String sValue, @Nonnegative int nMaxLength, @Nullable String sNewSuffix)
    • getToString

      @Nonnull public static String getToString(@Nullable Object aObject)
      Convert the passed object to a string using the Object.toString() method.
      Parameters:
      aObject - The value to be converted. May be null.
      Returns:
      An empty string in case the passed object was null. Never null.
      See Also:
    • getToString

      @Nullable public static String getToString(@Nullable Object aObject, @Nullable String sNullValue)
      Convert the passed object to a string using the Object.toString() method or otherwise return the passed default value.
      Parameters:
      aObject - The value to be converted. May be null.
      sNullValue - The value to be returned in case the passed object is null. May be null itself.
      Returns:
      The passed default value in case the passed object was null or the result of Object.toString() on the passed object.
      See Also:
    • getWithoutLeadingChar

      @Nonnull public static String getWithoutLeadingChar(@Nullable String sStr)
      Get the passed string without the first char.
      Parameters:
      sStr - The source string. May be null.
      Returns:
      An empty, non-null string 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 be null.
      nCount - The number of chars to remove.
      Returns:
      An empty, non-null string if the passed string has a length ≤ nCount.
    • getWithoutTrailingChar

      @Nonnull public static String getWithoutTrailingChar(@Nullable String sStr)
      Get the passed string without the last char.
      Parameters:
      sStr - The source string. May be null.
      Returns:
      An empty, non-null string 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 be null.
      nCount - The number of chars to remove.
      Returns:
      An empty, non-null string if the passed string has a length ≤ nCount.
    • getWithoutAnySpaces

      @Nonnull public static String getWithoutAnySpaces(@Nullable String sStr)
      Get the passed string where all spaces (white spaces or unicode spaces) have been removed.
      Parameters:
      sStr - The source string. May be null
      Returns:
      A non-null string representing the passed string without any spaces
    • getUntilFirstIncl

      @Nullable public static String getUntilFirstIncl(@Nullable String sStr, char cSearch)
      Get everything from the string up to and including the first passed char.
      Parameters:
      sStr - The source string. May be null.
      cSearch - The character to search.
      Returns:
      null if the passed string does not contain the search character.
    • getUntilFirstExcl

      @Nullable public static String getUntilFirstExcl(@Nullable String sStr, char cSearch)
      Get everything from the string up to and excluding first the passed char.
      Parameters:
      sStr - The source string. May be null.
      cSearch - The character to search.
      Returns:
      null if the passed string does not contain the search character.
    • getUntilFirstIncl

      @Nullable public static String getUntilFirstIncl(@Nullable String sStr, @Nullable String sSearch)
      Get everything from the string up to and including the first passed string.
      Parameters:
      sStr - The source string. May be null.
      sSearch - The string to search. May be null.
      Returns:
      null if the passed string does not contain the search string. If the search string is empty, the empty string is returned.
    • getUntilFirstExcl

      @Nullable public static String getUntilFirstExcl(@Nullable String sStr, @Nullable String sSearch)
      Get everything from the string up to and excluding the first passed string.
      Parameters:
      sStr - The source string. May be null.
      sSearch - The string to search. May be null.
      Returns:
      null if the passed string does not contain the search string. If the search string is empty, the empty string is returned.
    • getUntilLastIncl

      @Nullable public static String getUntilLastIncl(@Nullable String sStr, char cSearch)
      Get everything from the string up to and including the first passed char.
      Parameters:
      sStr - The source string. May be null.
      cSearch - The character to search.
      Returns:
      null if the passed string does not contain the search character.
    • getUntilLastExcl

      @Nullable public static String getUntilLastExcl(@Nullable String sStr, char cSearch)
      Get everything from the string up to and excluding first the passed char.
      Parameters:
      sStr - The source string. May be null.
      cSearch - The character to search.
      Returns:
      null if the passed string does not contain the search character.
    • getUntilLastIncl

      @Nullable public static String getUntilLastIncl(@Nullable String sStr, @Nullable String sSearch)
      Get everything from the string up to and including the first passed string.
      Parameters:
      sStr - The source string. May be null.
      sSearch - The string to search. May be null.
      Returns:
      null if the passed string does not contain the search string. If the search string is empty, the empty string is returned.
    • getUntilLastExcl

      @Nullable public static String getUntilLastExcl(@Nullable String sStr, @Nullable String sSearch)
      Get everything from the string up to and excluding the first passed string.
      Parameters:
      sStr - The source string. May be null.
      sSearch - The string to search. May be null.
      Returns:
      null if the passed string does not contain the search string. If the search string is empty, the empty string is returned.
    • getFromFirstIncl

      @Nullable public static String getFromFirstIncl(@Nullable String sStr, char cSearch)
      Get everything from the string from and including the first passed char.
      Parameters:
      sStr - The source string. May be null.
      cSearch - The character to search.
      Returns:
      null if the passed string does not contain the search character.
    • getFromFirstExcl

      @Nullable public static String getFromFirstExcl(@Nullable String sStr, char cSearch)
      Get everything from the string from and excluding the first passed char.
      Parameters:
      sStr - The source string. May be null.
      cSearch - The character to search.
      Returns:
      null if the passed string does not contain the search character.
    • getFromFirstIncl

      @Nullable public static String getFromFirstIncl(@Nullable String sStr, @Nullable String sSearch)
      Get everything from the string from and including the passed string.
      Parameters:
      sStr - The source string. May be null.
      sSearch - The string to search. May be null.
      Returns:
      null if the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
    • getFromFirstExcl

      @Nullable public static String getFromFirstExcl(@Nullable String sStr, @Nullable String sSearch)
      Get everything from the string from and excluding the passed string.
      Parameters:
      sStr - The source string. May be null.
      sSearch - The string to search. May be null.
      Returns:
      null if the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
    • getFromLastIncl

      @Nullable public static String getFromLastIncl(@Nullable String sStr, char cSearch)
      Get everything from the string from and including the first passed char.
      Parameters:
      sStr - The source string. May be null.
      cSearch - The character to search.
      Returns:
      null if the passed string does not contain the search character.
    • getFromLastExcl

      @Nullable public static String getFromLastExcl(@Nullable String sStr, char cSearch)
      Get everything from the string from and excluding the first passed char.
      Parameters:
      sStr - The source string. May be null.
      cSearch - The character to search.
      Returns:
      null if the passed string does not contain the search character.
    • getFromLastIncl

      @Nullable public static String getFromLastIncl(@Nullable String sStr, @Nullable String sSearch)
      Get everything from the string from and including the passed string.
      Parameters:
      sStr - The source string. May be null.
      sSearch - The string to search. May be null.
      Returns:
      null if the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
    • getFromLastExcl

      @Nullable public static String getFromLastExcl(@Nullable String sStr, @Nullable String sSearch)
      Get everything from the string from and excluding the passed string.
      Parameters:
      sStr - The source string. May be null.
      sSearch - The string to search. May be null.
      Returns:
      null if the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
    • getFirstToken

      @Nullable public static String getFirstToken(@Nullable String sStr, char cSearch)
      Get the first token up to (and excluding) the separating character.
      Parameters:
      sStr - The string to search. May be null.
      cSearch - The search character.
      Returns:
      The passed string if no such separator token was found.
    • getFirstToken

      @Nullable public static String getFirstToken(@Nullable String sStr, @Nullable String sSearch)
      Get the first token up to (and excluding) the separating string.
      Parameters:
      sStr - The string to search. May be null.
      sSearch - The search string. May be null.
      Returns:
      The passed string if no such separator token was found.
    • getLastToken

      @Nullable public static String getLastToken(@Nullable String sStr, char cSearch)
      Get the last token from (and excluding) the separating character.
      Parameters:
      sStr - The string to search. May be null.
      cSearch - The search character.
      Returns:
      The passed string if no such separator token was found.
    • getLastToken

      @Nullable public static String getLastToken(@Nullable String sStr, @Nullable String sSearch)
      Get the last token from (and excluding) the separating string.
      Parameters:
      sStr - The string to search. May be null.
      sSearch - The search string. May be null.
      Returns:
      The passed string if no such separator token was found.