Class StringCount

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

@Immutable public final class StringCount extends Object
Helper class for counting things in Strings
Author:
Philip Helger
  • Method Details

    • getCharCount

      @Nonnegative @UsedInGeneratedCode public static int getCharCount(@Nullable String s, char cSearch)
      Count the number of occurrences of a character in a String.
      Parameters:
      s - The string to search in. May be null.
      cSearch - The character to search for.
      Returns:
      The number of occurrences. Always ≥ 0.
    • getCharCount

      @Nonnegative public static int getCharCount(char @Nullable [] aChars, char cSearch)
      Count the number of occurrences of a character in a char array.
      Parameters:
      aChars - The char array to search in. May be null.
      cSearch - The character to search for.
      Returns:
      The number of occurrences. Always ≥ 0.
    • getLineCount

      @Nonnegative public static int getLineCount(@Nullable String s)
      Get the number of lines in the passed string, using '\n' as the line separator.
      Parameters:
      s - The string to count lines in. May be null.
      Returns:
      The number of lines. Always ≥ 1.
    • getLineCount

      @Nonnegative public static int getLineCount(@Nullable String s, char cLineSep)
      Get the number of lines in the passed string, using the specified line separator character.
      Parameters:
      s - The string to count lines in. May be null.
      cLineSep - The line separator character.
      Returns:
      The number of lines. Always ≥ 1.
    • getCharacterCount

      @Nonnegative public static int getCharacterCount(int nValue)
      Get the number of characters the passed value would occupy in a string representation.
      Copied from java.lang.Integer#StringSize
      Parameters:
      nValue - The integer value to check. May be be positive or negative.
      Returns:
      Number of characters required. Always > 0.
    • getCharacterCount

      @Nonnegative public static int getCharacterCount(long nValue)
      Get the number of characters the passed value would occupy in a string representation.
      Parameters:
      nValue - The long value to check. May be be positive or negative.
      Returns:
      Number of characters required. Always > 0.
    • getOccurrenceCount

      @Nonnegative public static int getOccurrenceCount(@Nullable String sText, @Nullable String sSearch)
      Count the number of occurrences of sSearch within sText.
      Parameters:
      sText - The text to search in. May be null.
      sSearch - The text to search for. May be null.
      Returns:
      A non-negative number of occurrences.
    • getOccurrenceCountIgnoreCase

      @Nonnegative public static int getOccurrenceCountIgnoreCase(@Nullable String sText, @Nullable String sSearch, @NonNull Locale aSortLocale)
      Count the number of occurrences 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:
      A non-negative number of occurrences.
    • getOccurrenceCount

      @Nonnegative @DevelopersNote("This is the same as getCharCount") public static int getOccurrenceCount(@Nullable String sText, char cSearch)
      Count the number of occurrences of cSearch within sText.
      Parameters:
      sText - The text to search in. May be null.
      cSearch - The character to search for.
      Returns:
      A non-negative number of occurrences.
    • getOccurrenceCountIgnoreCase

      @Nonnegative public static int getOccurrenceCountIgnoreCase(@Nullable String sText, char cSearch, @NonNull Locale aSortLocale)
      Count the number of occurrences of cSearch within sText ignoring case.
      Parameters:
      sText - The text to search in. May be null.
      cSearch - The character to search for.
      aSortLocale - The locale to be used for case unifying.
      Returns:
      A non-negative number of occurrences.
    • getLeadingWhitespaceCount

      @Nonnegative public static int getLeadingWhitespaceCount(@Nullable String s)
      Get the number of leading white spaces according to Character.isWhitespace(char)
      Parameters:
      s - The string to be parsed. May be null.
      Returns:
      Always ≥ 0.
    • getTrailingWhitespaceCount

      @Nonnegative public static int getTrailingWhitespaceCount(@Nullable String s)
      Get the number of trailing white spaces according to Character.isWhitespace(char)
      Parameters:
      s - The string to be parsed. May be null.
      Returns:
      Always ≥ 0.
    • getLeadingCharCount

      @Nonnegative public static int getLeadingCharCount(@Nullable String s, char c)
      Get the number of specified chars, the passed string starts with.
      Parameters:
      s - The string to be parsed. May be null.
      c - The char to be searched.
      Returns:
      Always ≥ 0.
    • getTrailingCharCount

      @Nonnegative public static int getTrailingCharCount(@Nullable String s, char c)
      Get the number of specified chars, the passed string ends with.
      Parameters:
      s - The string to be parsed. May be null.
      c - The char to be searched.
      Returns:
      Always ≥ 0.