Solved

Counting the number of lines in a text file

Posted on 2003-10-27
17
229 Views
Last Modified: 2010-04-16
I have a text file with a number of categories.

example

@jon,
Name = {jon},
Date = {22.02.83}
}
@peter,
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


Thanks

0
Comment
Question by:ab0u110a
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 2
  • +1
17 Comments
 
LVL 1

Accepted Solution

by:
jlach earned 85 total points
ID: 9629808
StreamReader streamRead = new StreamReader(@"FileNameHere.txt");
int count = 0;
string line = streamRead.ReadLine();
while (line != null) {
   count++;
   if (line == "}") {
      break;
   }
   else {
      line = streamRead.ReadLine();
   }
}

This should work for ya
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9629863
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
0
 
LVL 1

Expert Comment

by:jon6
ID: 9632387
Still having problems i cant get it to read from the last point it was at
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 10

Expert Comment

by:ptmcomp
ID: 9632405
\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)
0
 

Author Comment

by:ab0u110a
ID: 9632445
Could u write the code
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9632572
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.
0
 

Author Comment

by:ab0u110a
ID: 9632591
Thanks both of you for your help i have worked it out Jlachs code worked, but thanks for your help ptmcomp
0
 

Author Comment

by:ab0u110a
ID: 9632805
Sorry ptmcomp i still need your help i have realised that it has not worked it only reads the first lines each time
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9633093
Is this thread closed now? I got confused by the last comment.
0
 

Author Comment

by:ab0u110a
ID: 9633534
i have awarded points thinking that it was working but it does not work
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9633598
So what are we gonna do?
0
 

Author Comment

by:ab0u110a
ID: 9633681
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
0
 

Author Comment

by:ab0u110a
ID: 9634513
i am going to ask for the points back, if i do will you answer the question with code on how to do it
0
 
LVL 1

Expert Comment

by:jlach
ID: 9634991
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
0
 

Author Comment

by:ab0u110a
ID: 9635056
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
0
 

Author Comment

by:ab0u110a
ID: 9636588
jlach

i dont have your msn messenger contact can you send me an email, the  code works perfectly thanks so much
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9636786
I can also help to make jlach's version work. Just I don't have a lot of time this and next two weeks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
orderby list (from Json) 1 44
GET INFO ABOUT WHAT THE PRINTER IS DOING ? 11 76
Need a quick overview of Selenium testing 2 35
SQL State HYT00. Timeout expired proplem 8 44
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question