Android - java - count words

android, java, string

Solution

You want to split on arbitrary strings of whitespace, rather than just space characters. So, use `.split("\\s+")` instead of `.split(" ")`.

Problem

I have an edittext and I want to count the words in it. There is something wrong when there are new lines in the edittext. I tried this: ``` String[] WC = et_note.getText().toString().split(" "); Log.i("wordcount", "wc: " + WC.length); ``` This is a text -> wc: 4 This is a text -> wc: 4 This is a simple text -> wc: 4 Any ideas?

Original source