1

文字列内の単語 (一部のキーワードを除く) の頻度をカウントし、DESC で並べ替えたいと思います。それで、どうすればできますか?

次の文字列では...

This is stackoverflow. I repeat stackoverflow.

除外キーワードの場所

ExKeywords() ={"i","is"}

出力は次のようになります

stackoverflow  
repeat         
this           

PSいいえ!私はグーグルを再設計していません!:)

4

2 に答える 2

4
string input = "This is stackoverflow. I repeat stackoverflow.";
string[] keywords = new[] {"i", "is"};
Regex regex = new Regex("\\w+");

foreach (var group in regex.Matches(input)
    .OfType<Match>()
    .Select(c => c.Value.ToLowerInvariant())
    .Where(c => !keywords.Contains(c))
    .GroupBy(c => c)
    .OrderByDescending(c => c.Count())
    .ThenBy(c => c.Key))
{
    Console.WriteLine(group.Key);
}
于 2010-08-31T09:55:59.523 に答える
0
string s = "This is stackoverflow. I repeat stackoverflow.";
string[] notRequired = {"i", "is"};

var myData =
    from word in s.Split().Reverse()
    where (notRequired.Contains(word.ToLower()) == false)
    group word by word into g
    select g.Key;

foreach(string item in myData)
    Console.WriteLine(item);
于 2010-08-31T10:16:25.393 に答える