fun countOccurrences(str: String, word: String): Int {
return str.split("\\s+".toRegex()).filter { it == word }.count()
}
fun main() {
val str = "Kotlin programming language. Kotlin cross-platform. Kotlin statically typed"
val word = "Kotlin"
println("Occurrences of '$word': ${countOccurrences(str, word)}")
}
/*
run:
Occurrences of 'Kotlin': 3
*/