countWords method

int countWords()

Counts the number of words in the string.

Example:

print("Hello Flutter Developer".countWords()); // 3

Implementation

int countWords() {
  if (validate().isEmptyOrNull) return 0;
  return this!.split(RegExp('\\s+')).length;
}