0

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

3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by Phaelax
1

>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.jspa?threadID=474733&messageID=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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.