Created
October 10, 2019 02:02
-
-
Save kyrathasoft/94502eb12ce987793e82f6d6634e908b to your computer and use it in GitHub Desktop.
demonstrates counting number of words in a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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