Last active
February 16, 2017 05:36
-
-
Save masaru-b-cl/ebd3b2a52a75b9dc1aa4c85501e64fc7 to your computer and use it in GitHub Desktop.
"与えられた文字列中に含まれる単語の個数を単語ごとにカウントする"LINQ
This file contains hidden or 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
<Query Kind="Expression" /> | |
"I have a pen. I have a apple. oh!! Apple pen! I have a pen. I have a pineapple. oh!! Pineapple pen! Apple pen. Pineapplepen. Pen pineapple apple pen." | |
.Split(' ') | |
.Select(s => Regex.Replace(s, "[\\.!]", "")) | |
.Select(s => s.ToLower()) | |
.ToLookup(w => w) | |
.Select(g => new { Word = g.Key, Count = g.Count()}) | |
// Word | Count | |
// ------------ | ------ | |
// i | 4 | |
// have | 4 | |
// a | 4 | |
// pen | 7 | |
// apple | 4 | |
// oh | 2 | |
// pineapple | 3 | |
// pineapplepen | 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment