Issue
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 simple
text -> wc: 4
Any ideas?
Solution
You want to split on arbitrary strings of whitespace, rather than just space characters. So, use .split("\\s+")
instead of .split(" ")
.
Answered By - Gareth McCaughan
Answer Checked By - Willingham (JavaFixing Volunteer)