I take a string with integer count
int count=0;
string s="wow"
and i am using foreach loop to count number of characters in a specified string
foreach(char ch in s)
{
count++
}
so how can i count those characters which are repeated in my string like 'w'.
答案 0 :(得分:3)
Do like this
string s="wow";
int repeats= s.Length - s.ToCharArray().Distinct().Count();
答案 1 :(得分:3)
Try this )
string test = "aababc";
var result = test.GroupBy(c => c).Where(c => c.Count() > 1).Select(c => new { charName = c.Key, charCount = c.Count()});