w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Get total number of non-blank lines from text file?

You can use String.IsNullOrWhiteSpace method with Count:

File.ReadLines(@"file.txt").Count(line =>
!string.IsNullOrWhiteSpace(line));

Or another way with All and char.IsWhiteSpace:

File.ReadLines(@"file.txt").Count(line =>
!line.All(char.IsWhiteSpace));




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.