test: CountCharTest (#5423)

test: CountCharTest

Co-authored-by: alxkm <alx@alx.com>
This commit is contained in:
Alex Klymenko
2024-08-28 18:45:23 +02:00
committed by GitHub
parent b2815db5cd
commit 0733075498
2 changed files with 20 additions and 9 deletions

View File

@ -5,13 +5,16 @@ public final class CountChar {
}
/**
* Count non space character in string
* Counts the number of non-whitespace characters in the given string.
*
* @param str String to count the characters
* @return number of character in the specified string
* @param str the input string to count the characters in
* @return the number of non-whitespace characters in the specified string;
* returns 0 if the input string is null
*/
public static int countCharacters(String str) {
if (str == null) {
return 0;
}
return str.replaceAll("\\s", "").length();
}
}