Skip to content

Commit

Permalink
Simplify file processing by using File.ReadLines
Browse files Browse the repository at this point in the history
  • Loading branch information
josepho0918 committed May 31, 2024
1 parent f3ee0f3 commit cf17573
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions TrimTail/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ public class Program

public static bool HasTrailingBlanks(in string filePath)
{
using var file = File.OpenText(filePath);
string? line;
while ((line = file.ReadLine()) != null)
foreach (var line in File.ReadLines(filePath))
{
if (!string.IsNullOrEmpty(line) && char.IsWhiteSpace(line[^1]))
{
Expand All @@ -23,7 +21,7 @@ public static void RemoveTrailingBlanks(in string filePath)
{
if (!HasTrailingBlanks(filePath)) return;

string tempPath = Path.GetTempFileName();
var tempPath = Path.GetTempFileName();
using (var origFile = File.OpenText(filePath))
using (var tempFile = File.CreateText(tempPath))
{
Expand Down

0 comments on commit cf17573

Please sign in to comment.