Home > Software engineering >  How to count word in TextView Android Studio [duplicate]
How to count word in TextView Android Studio [duplicate]

Time:09-17

Suppose In my app I have two textview, first one name is ViewText and the second one is WordCount.

I want to show some text in ViewText and WordCount shows how many words in ViewText.

Here is an example of my UI.

How can I count words in textview in Android Studio?

CodePudding user response:

Try this one

val words = "Hi this is sentence for counting words"
var totalCount = words.split("\\s ".toRegex()).size
println(totalCount)

  • Related