Skip to content

Instantly share code, notes, and snippets.

@kyrathasoft
Created October 10, 2019 02:02
Show Gist options
  • Save kyrathasoft/94502eb12ce987793e82f6d6634e908b to your computer and use it in GitHub Desktop.
Save kyrathasoft/94502eb12ce987793e82f6d6634e908b to your computer and use it in GitHub Desktop.
demonstrates counting number of words in a string
using System;
namespace Example {
class Program {
static void Main(string[] args){
string p = "This is a brief sample sentence.";
string[] words = p.Split(default(Char[]), StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine(" The following sentence contains {0} words:", words.Length);
Console.WriteLine(" {0}", p);
p = "This is a not so brief sample sentence containing more embellishment.";
words = p.Split(default(Char[]), StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine(" The following sentence contains {0} words:", words.Length);
Console.WriteLine(" {0}", p);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment