Solutions
The following sections describe solutions to the preceding problems. You can download the example solutions to see additional details and to experiment with the programs at https://github.com/PacktPublishing/Improving-your-C-Sharp-Skills/tree/master/Chapter17.
29. Removing blank lines
The following RemoveBlankLines
method removes the blank lines from a file:
// Remove the empty lines from the indicated file. private void RemoveBlankLines(string filename, out int numBlankLines, out int numNonBlankLines) { // Read the file. string[] lines = File.ReadAllLines(filename); int totalLines = lines.Length; // Remove blank lines. List<string> nonblankLines = new List<string>(); foreach (string line in lines) if (line.Trim().Length > 0) nonblankLines.Add(line); // Write the processed file. numNonBlankLines = nonblankLines.Count; numBlankLines = totalLines - numNonBlankLines; File.WriteAllLines(filename, nonblankLines...