Package com.helger.base.string
Class StringCount
java.lang.Object
com.helger.base.string.StringCount
Helper class for counting things in Strings
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic intgetCharacterCount(int nValue) Get the number of characters the passed value would occupy in a string representation.
Copied from java.lang.Integer#StringSizestatic intgetCharacterCount(long nValue) Get the number of characters the passed value would occupy in a string representation.static intgetCharCount(char @Nullable [] aChars, char cSearch) Count the number of occurrences of a character in a char array.static intgetCharCount(@Nullable String s, char cSearch) Count the number of occurrences of a character in a String.static intgetLeadingCharCount(@Nullable String s, char c) Get the number of specified chars, the passed string starts with.static intgetLeadingWhitespaceCount(@Nullable String s) Get the number of leading white spaces according toCharacter.isWhitespace(char)static intgetLineCount(@Nullable String s) Get the number of lines in the passed string, using '\n' as the line separator.static intgetLineCount(@Nullable String s, char cLineSep) Get the number of lines in the passed string, using the specified line separator character.static intgetOccurrenceCount(@Nullable String sText, char cSearch) Count the number of occurrences of cSearch within sText.static intgetOccurrenceCount(@Nullable String sText, @Nullable String sSearch) Count the number of occurrences of sSearch within sText.static intgetOccurrenceCountIgnoreCase(@Nullable String sText, char cSearch, @NonNull Locale aSortLocale) Count the number of occurrences of cSearch within sText ignoring case.static intgetOccurrenceCountIgnoreCase(@Nullable String sText, @Nullable String sSearch, @NonNull Locale aSortLocale) Count the number of occurrences of sSearch within sText ignoring case.static intgetTrailingCharCount(@Nullable String s, char c) Get the number of specified chars, the passed string ends with.static intgetTrailingWhitespaceCount(@Nullable String s) Get the number of trailing white spaces according toCharacter.isWhitespace(char)
-
Method Details
-
getCharCount
Count the number of occurrences of a character in a String.- Parameters:
s- The string to search in. May benull.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 benull.cSearch- The character to search for.- Returns:
- The number of occurrences. Always ≥ 0.
-
getLineCount
Get the number of lines in the passed string, using '\n' as the line separator.- Parameters:
s- The string to count lines in. May benull.- Returns:
- The number of lines. Always ≥ 1.
-
getLineCount
Get the number of lines in the passed string, using the specified line separator character.- Parameters:
s- The string to count lines in. May benull.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
Count the number of occurrences of sSearch within sText.- Parameters:
sText- The text to search in. May benull.sSearch- The text to search for. May benull.- 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 benull.sSearch- The text to search for. May benull.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 benull.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 benull.cSearch- The character to search for.aSortLocale- The locale to be used for case unifying.- Returns:
- A non-negative number of occurrences.
-
getLeadingWhitespaceCount
Get the number of leading white spaces according toCharacter.isWhitespace(char)- Parameters:
s- The string to be parsed. May benull.- Returns:
- Always ≥ 0.
-
getTrailingWhitespaceCount
Get the number of trailing white spaces according toCharacter.isWhitespace(char)- Parameters:
s- The string to be parsed. May benull.- Returns:
- Always ≥ 0.
-
getLeadingCharCount
Get the number of specified chars, the passed string starts with.- Parameters:
s- The string to be parsed. May benull.c- The char to be searched.- Returns:
- Always ≥ 0.
-
getTrailingCharCount
Get the number of specified chars, the passed string ends with.- Parameters:
s- The string to be parsed. May benull.c- The char to be searched.- Returns:
- Always ≥ 0.
-