int GetNumberOfLinesForRange (string fileContents, int index, int length)
{
int lines = 0;
int stop = index + length;
char c;
bool foundCR = false;
for (int pos = index; pos < stop; pos++) {
c = fileContents [pos];
if (c == '\n' || foundCR) {
lines++;
foundCR = false;
}
foundCR = (c == '\r');
}
return lines;
}