во-первых, вы можете изменить
while (pos < EntireFile.Length && (/*curr = */EntireFile.Substring(pos, EntireFile.Length - pos)).Contains(" class"))
{
...
}
на
var loweredEntireFile = EntireFile.ToLower();
while (pos < loweredEntireFile.Length &&
Regex.IsMatch(loweredEntireFile, " class",
RegexOptions.IgnoreCase)
{
...
// we just need to process the rest of the file
loweredEntireFile = loweredEntireFile.Substring(pos, loweredEntireFile.Length - pos));
}
, а затем изменить
pos = EntireFile.ToLower().IndexOf(" class", pos) + 6;
int end11 = EntireFile.ToLower().IndexOf("extends", pos);
на
var matches = Regex.Matchs(loweredEntireFile, " class", RegexOptions.IgnoreCase);
pos = matches.First().Index;
matches = Regex.Matchs(loweredEntireFile, "extends", RegexOptions.IgnoreCase);
var end11 = matches.First().Index;
как другоеПредполагается, что
var loweredEntiredFile = EntiredFile.ToLower();
следует выполнить один раз за пределами while, а
loweredEntireFile = loweredEntireFile.Substring(pos, loweredEntireFile.Length - pos));
необходимо выполнить в конце while