C# - Count paragraphs in text file

November 4, 2012 at 01:50:43
Specs: Windows XP, 2.798 GHz / 511 MB
Hello,

I've started with C# and need help.

I have to count the paragraphs in a textfile, but i'm failing.

::name.txt
sometext
sometext
sometext

sometext
sometext
sometext

sometext
sometext
--END

In this example I have 3 paragraphs, but how do I count it?

It should look to the newline to recover what is a new paragraph, if u know what I mean.

All help is welcome,

Regards,

Happy is ONE who says I am an OttoMAN.


See More: C# - Count paragraphs in text file

Report •

#1
November 4, 2012 at 01:57:43
Just search through the characters of the file to find pairs of CR/LFs.

Report •

#2
November 4, 2012 at 02:05:40
Hello ijack,

Thank-you for your fast reply.

But I dont know how I can do that, maybe you can show me?

Regards,

Happy is ONE who says I am an OttoMAN.


Report •

#3
November 4, 2012 at 02:16:58
Read the file into a string; iterate through the characters in the string.

Either this is a homework question or you are trying to learn C# by yourself. In either event you will learn more by doing a little research than by copying an answer parrot fashion, so I'm not going to give a more detailed reply.


Report •

Related Solutions

#4
November 4, 2012 at 02:34:29
Before argumenting this is homework or not, I have tried this for 1 hour atm, searched on the internet and could not find an proper answer.
Thats why I'm posting here, cuz I cant continue..

Happy is ONE who says I am an OttoMAN.


Report •

#5
November 4, 2012 at 03:31:54
Well, I think you need to brush up on your search skills.

Google "C# read text file". The first hit will give you the answer, together with an example, of how to read a text file into a string. Now the rest is up to you - it is clear from your answer that this is homework and I have no intention of doing it for you.


Report •

#6
November 4, 2012 at 03:48:49
Your Google-fu is weak. I suggest regular expressions.
https://www.google.com/#q=c%23+regu...

How To Ask Questions The Smart Way


Report •

Ask Question