number of words in String

PHOTO EMBED

Fri Sep 23 2022 22:45:07 GMT+0000 (UTC)

Saved by @Coder_x #kotlin

fun main() {
    print(countWords("Return number of words in String"))
}

fun countWords( txt: String):Int {
    
    var totalWords = txt.trim().split("\\s+".toRegex()).size
    
    return totalWords              
}
content_copyCOPY