Get leading whitespace
I just wrote this method and I'm wondering if something similar already exists in the framework? It just seems like one of those methods... If not, is there a better way to do it? /// <summary> /// Return the whitespace at the start of a line. /// </summary> /// <param name="trimToLowerTab">Round the number of spaces down to the nearest multiple of 4.</param> public string GetLeadingWhitespace(string line, bool trimToLowerTab = true) { int whitespace = 0; foreach (char ch in line) { if (ch != ' ') break; ++whitespace; } if (trimToLowerTab) whitespace -= whitespace % 4; return "".PadLeft