private static int CountWords(string content)
{
if (string.IsNullOrEmpty(content))
{
return 0;
}
int count = 0;
for (int i = 1; i < content.Length; i++)
{
if (char.IsWhiteSpace(content[i - 1]) &&
(char.IsLetter(content[i]) || char.IsPunctuation(content[i])))
{
count += 1;
}
}
}
public static int getWordsCount(string sentence)
{
System.Text.RegularExpressions.MatchCollection matchCollection = System.Text.RegularExpressions.Regex.Matches(sentence, @"[\S]+");
return matchCollection.Count;
}
sentence.Split(new char[] {'\r', '\n', ' '}, StringSplitOptions.RemoveEmptyEntries).Length;