this language has me suffering, I can't find how to do it. Does anyone have any idea how to count words in DART or how to count empty spaces?
string micadena ="Hola mundo soy Aldahir";
int longitud = " ".allmatches(micadena).lenght;
return longitud;
I have this, this tells me the number of specific letters eg, a, b, c, d and so on... but what I want is to count the spaces to know the number of words, or if there is any other function to know the number of words.
You could use the method
split
ofString
, what it does is split the string according toString
what you pass to it.The problem is that it could give you unexpected results if there is more than one space between the words.
If you don't want to have any problems, you could use a regular expression:
With that you will not have errors.