1

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'.

Vivacity InfoTech
  • 465
  • 3
  • 11
  • 25
  • 1
    @xanatos Honestly, title and question say different things. Title says; _how to find duplicate characters_ but question says _how to count duplicate characters_. But seems like both doesn't covered in the duplicate question. Re-opened. My bad. – Soner Gönül Jun 26 '15 at 10:32

2 Answers2

6

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()});
Disappointed
  • 1,100
  • 1
  • 9
  • 21
4

Do like this

  string s="wow";
  int repeats= s.Length - s.ToCharArray().Distinct().Count();
tariq
  • 2,193
  • 15
  • 26