944,178 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 10589
  • Java RSS
May 8th, 2006
0

# of lines in a text file

Expand Post »
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
Similar Threads
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
May 8th, 2006
1

Re: # of lines in a text file

>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).

Java Syntax (Toggle Plain Text)
  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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
May 8th, 2006
0

Re: # of lines in a text file

Thanks a lot!
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
May 8th, 2006
0

Re: # of lines in a text file

String.startsWith(str)
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: calling a the method
Next Thread in Java Forum Timeline: Copying .class files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC