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++) {
Make it an instance method, if you'll use it in a loop.