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

Member Avatar for iamthwee

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

Thanks a lot!

String.startsWith(str)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.