# of lines in a text file

Reply

Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 6
Dark_Omen Dark_Omen is offline Offline
Posting Pro

# of lines in a text file

 
0
  #1
May 8th, 2006
Hello,

I was wondering if there was a way to find how many lines there are in a text file, and if so can you find out how many lines in the text file start with a particular word (an identifier).

Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: # of lines in a text file

 
1
  #2
May 8th, 2006
>I was wondering if there was a way to find how many lines there are in a text file...

http://forum.java.sun.com/thread.jsp...sageID=2200710

However, speed might not be an issue here.

>so can you find out how many lines in the text file start with a particular word (an identifier).

  1. class indexTest
  2. {
  3. public static void main (String args[])
  4. {
  5. String str = "This string will be searched";
  6. String find = "will";
  7.  
  8. System.out.println (str.indexOf ('s')); // find char, no offset
  9. System.out.println (str.lastIndexOf ('s', 4)); // find s, offset by 9
  10.  
  11. System.out.println (str.indexOf (find)); // find the string find, no offset
  12. System.out.println (str.lastIndexOf(find)); // find the string find in str, no offset
  13. }
  14. }

For more advanced work with strings check out the Stringbuffer api.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 6
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: # of lines in a text file

 
0
  #3
May 8th, 2006
Thanks a lot!
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: # of lines in a text file

 
0
  #4
May 8th, 2006
String.startsWith(str)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC