This method can return the zero-based index of longest run in a string. The run is a consecutive sequence of the same characters. If there are more (longest) run with same character then returns with the first index of the run. I used Regular expression which matches patterns with input string.
public static int IndexOfLongestRun(string str)
{
StringBuilder pattern = new StringBuilder();
pattern.Append(@"([a-z])" + new string('*', str.Length - 1));
pattern=pattern.Replace("*",@"\1");
Match m = null;
for (int i = (pattern.Length-7); i > 0; i--)
{
pattern = pattern.Remove(pattern.Length-2,1);
m = Regex.Match(str, pattern.ToString());
if (m.ToString() != "") break;
}
return str.IndexOf(m.ToString());
}