Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • It will find first double letter, won't it? Commented Feb 8, 2016 at 5:26
  • @Backs In C# you can extract all the occurrences. Different ones. Commented Feb 8, 2016 at 5:28
  • @Backs expanded an answer with example. Commented Feb 8, 2016 at 5:32
  • @DiligentKeyPresser, your answer works perfect, i just need to replace my for loop with this one line d+=System.Text.RegularExpressions.Regex.Matches(s,@"(.)\1").Count; but i need to compare with a linq version of this, then i do a performance comparison to come up with the final solution. Commented Feb 8, 2016 at 5:40
  • @DiligentKeyPresser - Good answer. This works nicely to compute the actual value required - Regex.Matches(word, @"(.)\1").Cast<Match>().Select(m => m.Length / 2).Sum() Commented Feb 8, 2016 at 10:53