Click here to Skip to main content
15,884,018 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to count no of blank line in a text file?
Thanku in advance.
Posted
Comments
[no name] 30-Mar-15 6:09am    
You need empty spaces in a string?

Try this one

C#
var inptuFileName = "C:\test.txt"";
var lines = File.ReadAllLines(inptuFileName).Where(arg = > string.IsNullOrWhiteSpace(arg));
int count  = lines.Count();
 
Share this answer
 
v2
Comments
Maciej Los 30-Mar-15 7:24am    
+5I'd suggest to use only single variable:
int CountOfEmptyLines = File.ReadAllLines("FullFileName").Where(arg = > string.IsNullOrWhiteSpace(arg)).Count();
There really isn't a nice way! :laugh:
This: Counting Lines in a String[^] shows a number of ways to count lines, and it wouldn't be difficult for you to modify any of those to count blank lines.

But there is no simple solution: "lines" don't really exist in text files, they are just a convention of the software which processes them and uses the "line separator character" to distinguish between them!
 
Share this answer
 
Comments
[no name] 30-Mar-15 6:19am    
Mr OriginalGriff,i a m trying to Upvote your answer.still it's displaying a confirmed email message.but i didn't get any mail from codeproject.what i do for upvoting?
OriginalGriff 30-Mar-15 6:25am    
Well if you got this message as an email, then you entered the email address correctly! :laugh:
If you didn't, then check your settings - top right of this page, hover over your user name, click "My Settings" and it'll show you the email address you used.
If you need to change it, do so and it should send you a confirmation (I think - I haven't changed email for years)

If you need another confirmation sent, then you probably need to ask here:
http://www.codeproject.com/suggestions.aspx
The admins read everything there and they can check the email system and resend if necessary. (But bear in mind they are probably in Canada, so there could be time differences between your post and their reading it)
[no name] 30-Mar-15 6:31am    
k,no probs.i am already checked my settings it's visible my correct email id :)
OriginalGriff 30-Mar-15 6:38am    
I've just noticed that you signed up over a year ago - so presumably it's all been working since then?

Have you tried logging out and logging back in again, in case it's a cookie problem?
[no name] 30-Mar-15 6:45am    
I am active in every time.no i post a bug in suggestion.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900