Just add 2 pence, here is an alternative using Regex:
string source = "eeabccdeeeeef"; Regex reg = new Regex(@"(\w)\1+"); MatchCollection matches = reg.Matches(source); int longest = 0; foreach (System.Text.RegularExpressions.Match match in matches) { if (longest < match.Length) longest = match.Length; }
Due to the fact that I didn’t read the question correctly in the first place when sending my previous answer, I should probably add some actual feedback, given that the question posed by the OP. However, every item I came up with is mentioned by Henrik or Job Skeet, so I just emphasize what John Skeet did; you don't need to convert the string to a char array, you can just index a specific point in the string as follows:
char letter = someString[4];
So everything should work if you replace strChars with strPass .
source share