User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 391,998 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,201 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1706 | Replies: 3
Reply
Join Date: Apr 2004
Posts: 555
Reputation: Dark_Omen is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 6
Dark_Omen Dark_Omen is offline Offline
Posting Pro

# of lines in a text file

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,667
Reputation: iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice 
Rep Power: 16
Solved Threads: 298
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: # of lines in a text file

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

class indexTest
{
	public static void main (String args[])
	{
	String str = "This string will be searched";
	String find = "will";

	System.out.println (str.indexOf ('s'));  // find char, no offset
	System.out.println (str.lastIndexOf ('s', 4)); // find s, offset by 9

	System.out.println (str.indexOf (find)); // find the string find, no offset
	System.out.println (str.lastIndexOf(find)); // find the string find in str, no offset
	}
}

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

Re: # of lines in a text file

  #3  
May 8th, 2006
Thanks a lot!
Reply With Quote  
Join Date: Mar 2004
Posts: 715
Reputation: Phaelax is on a distinguished road 
Rep Power: 6
Solved Threads: 28
Phaelax Phaelax is offline Offline
Master Poster

Re: # of lines in a text file

  #4  
May 8th, 2006
String.startsWith(str)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Java Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 10:02 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC