Search This Blog

Monday, September 29, 2025

WordCount

 public void wordcount()
{
    //> Given a sentence, count how many times each word appears.
    //> *(Like "This is a test. This test is simple." → \`"This=2, is=2, test=2, simple=1" *)
    string s1 = "This is a test. This test is simple.";
    var charc1 = s1.Replace(".", "").Split(" ");
    var d1 = charc1
        .GroupBy(x => x)
        .ToDictionary(x => x.Key, y => y.Count());
}

No comments:

Post a Comment