Is there a way to improve this:
private static int CountNewlines(string s) { int len = s.Length; int c = 0; for (int i=0; i < len; i++) {
you could convert the string to a char array with "ToCharArray();" but i don't think it will improve the performance.. you could try to use unsafe code (pointer) instead of for but well that has its drawbacks to.