C# How To Count Words in a String
Count Words
Use the Split() method to split the sentence at each space, and count the words:
Example
string text = "I love learning C#";
string[] words = text.Split(' ');
Console.WriteLine("Number of words: " + words.Length);
Explanation:Split(' ') cuts the string at each space, and returns the words in an array.Length gives the number of elements in the array, which is the number of words.