title: how to count the number of words in Kotlin Android?
body: <p>I have tried to read this thread: <a href="https://stackoverflow.com/questions/10402948/android-java-count-words">Android - java - count words</a></p>
  
  <p>but it doesn't work for me.</p>
  
  <p>so let say I have these words in the android multiline edit text:</p>
  
  <hr>
  
  <p>I</p>
  
  <p>am </p>
  
  <p>very very</p>
  
  <p>happy</p>
  
  <p>right now</p>
  
  <hr>
  
  <p>so I want to count the number of words and then get integer '7' from that multiline edit text. how to do that ?</p>
  
  <p>I have tried this, but it doesn't work:</p>
  
  <pre><code>multilineEditText.addTextChangedListener(object: TextWatcher {
  
              override fun afterTextChanged(s: Editable?) {
  
              }
  
              override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
  
              }
  
              override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
  
                  val words = s.toString().trim()
                  numberOfInputWords = words.split("\\s+").first().length
                  wordsCounterTextView.text = "$numberOfInputWords"
  
  
              }
  
          })
  </code></pre>
  
  <p>but this code doesn't work for me, because it doesn't show the right number.</p>
  
  <p>from the thread <a href="https://stackoverflow.com/questions/10402948/android-java-count-words">Android - java - count words</a> </p>
  
  <p>it is said that I can use <code>someString.split("\\s+").length</code></p>
  
  <p>but I can't access <code>.length</code> after using <code>.split("\\s+")</code>. like this</p>
  
  <p><a href="https://i.stack.imgur.com/BFy19.png" rel="noreferrer"><img src="https://i.stack.imgur.com/BFy19.png" alt="enter image description here"></a></p>
  
  <p>thats why I use <code>first()</code> in my code, even though it doesn't work either.</p>