firstly you can change
while (pos < EntireFile.Length && (/*curr = */EntireFile.Substring(pos, EntireFile.Length - pos)).Contains(" class")) { ... }
to
var loweredEntireFile = EntireFile.ToLower(); while (pos < loweredEntireFile.Length && Regex.IsMatch(loweredEntireFile, " class", RegexOptions.IgnoreCase) { ...
then change
pos = EntireFile.ToLower().IndexOf(" class", pos) + 6; int end11 = EntireFile.ToLower().IndexOf("extends", pos);
to
var matches = Regex.Matchs(loweredEntireFile, " class", RegexOptions.IgnoreCase); pos = matches.First().Index; matches = Regex.Matchs(loweredEntireFile, "extends", RegexOptions.IgnoreCase); var end11 = matches.First().Index;
as expected
var loweredEntiredFile = EntiredFile.ToLower();
should be executed once outside the while, and
loweredEntireFile = loweredEntireFile.Substring(pos, loweredEntireFile.Length - pos));
must be done at the end of while
source share