private static int IndexOfFirstCorrectChar(string s) { int index = 0; while ((index < s.Length) && (s[index] == '_')) { index++; } // it's possible that we won't find one, e.g. something called "_" return (index == s.Length) ? 0 : index; } }