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++) {
This is probably the most efficient option - the item accessor is internally optimized and you can treat it as if it performs pointer arithmentic.