Counting the number of lines in a text file

I have a text file with a number of categories.


Name = {jon},
Date = {22.02.83}
Name = {peter}
Date = {29.10.82}

i have a utility in C# for reading in this text file, but it reads in at set number of lines, an add utility allow more lines to be added.

Does anyone know how i can count the number of lines till i reach the } on its own, do some work then start counting the nuber of line from the next @ symbol


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StreamReader streamRead = new StreamReader(@"FileNameHere.txt");
int count = 0;
string line = streamRead.ReadLine();
while (line != null) {
   if (line == "}") {
   else {
      line = streamRead.ReadLine();

This should work for ya

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Use regular expressions with multiline option.  
"\Z" matches the line ends, so match all line ends from "^@" till "}\Z". To count you can use groups or callback event
Still having problems i cant get it to read from the last point it was at
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

\G Specifies that the match must occur at the point where the previous match ended. When used with Match.NextMatch(), this ensures that matches are all contiguous. (From SDK Help under "regular expressions, atomic zero-width assertions" - you can also find it on MSDN)
ab0u110aAuthor Commented:
Could u write the code
Can you post the code you made so far then I can add what's missing. - Sorry, I don't have a lot of time at the moment.
ab0u110aAuthor Commented:
Thanks both of you for your help i have worked it out Jlachs code worked, but thanks for your help ptmcomp
ab0u110aAuthor Commented:
Sorry ptmcomp i still need your help i have realised that it has not worked it only reads the first lines each time
Is this thread closed now? I got confused by the last comment.
ab0u110aAuthor Commented:
i have awarded points thinking that it was working but it does not work
So what are we gonna do?
ab0u110aAuthor Commented:
i dont know i have no points left, it does not matter i can understand you would not want to help for no points, i will wait till i can buy points and ask the question again and give you the points
ab0u110aAuthor Commented:
i am going to ask for the points back, if i do will you answer the question with code on how to do it
ab0u110a ... im going to post a question.. i'll name it Points for ab0u11a .. say suttin in it, and you can have the points back.. if my answer is crap, i dont want the points, i dont deserve em =] heh
ab0u110aAuthor Commented:
Your answer was not crap but i thought it was working, but it was reading from the start of the file and i did not realise, it is a fundermental part of my program and must have it working correctly thanks for your help though, and for your honest nature in returning the points
ab0u110aAuthor Commented:

i dont have your msn messenger contact can you send me an email, the  code works perfectly thanks so much
I can also help to make jlach's version work. Just I don't have a lot of time this and next two weeks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.