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[] aChars, char cSearch) static intgetCharCount(String s, char cSearch) static intgetLeadingCharCount(String s, char c) Get the number of specified chars, the passed string starts with.static intGet the number of leading white spaces according toCharacter.isWhitespace(char)static intstatic intgetLineCount(String s, char cLineSep) static intgetOccurrenceCount(String sText, char cSearch) Count the number of occurrences of cSearch within sText.static intgetOccurrenceCount(String sText, String sSearch) Count the number of occurrences of sSearch within sText.static intgetOccurrenceCountIgnoreCase(String sText, char cSearch, Locale aSortLocale) Count the number of occurrences of cSearch within sText ignoring case.static intgetOccurrenceCountIgnoreCase(String sText, String sSearch, Locale aSortLocale) Count the number of occurrences of sSearch within sText ignoring case.static intgetTrailingCharCount(String s, char c) Get the number of specified chars, the passed string ends with.static intGet the number of trailing white spaces according toCharacter.isWhitespace(char)
-
Method Details
-
getCharCount
-
getCharCount
@Nonnegative public static int getCharCount(@Nullable char[] aChars, char cSearch) -
getLineCount
-
getLineCount
-
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.
-