import scala.util.Try
def countWhitespaceCharacters(str: String): Int = {
str.count(_.isWhitespace)
}
val str = "Scala \n Programming \r Language \t "
println(s"Total white spaces: ${countWhitespaceCharacters(str)}")
/*
run:
Total white spaces: 10
*/