package main
import (
"fmt"
"unicode"
)
func countWhitespaceCharacters(str string) int {
count := 0
length := len(str)
for i := 0; i < length; i++ {
if unicode.IsSpace(rune(str[i])) {
count++
}
}
return count
}
func main() {
str := "Golang \n Programming \r Language \t "
fmt.Println("Total white spaces:", countWhitespaceCharacters(str))
}
/*
run:
Total white spaces: 10
*/