配列に存在する文字列の数を数えています-
Tags = "the cat the mat the sat";
string[] words = Tags.Split(' ');
int counter = 0;
foreach (string item in words)
{
if (item != "")
{
counter++;
}
}
ただし、すべての文字列の出現をカウントするようにコードを変更するにはどうすればよいでしょうか。たとえば、
- 「その」= 3
- 「猫」= 1
- 「マット」= 1
- 「土」= 1
そして、これらの値を何らかの方法で保存しますか?