Hi
Can anyone let me know how to count the number of words in a file for example "hello" in a file
Thanks
Raj
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hi
Can anyone let me know how to count the number of words in a file for example "hello" in a file
Thanks
Raj
Of course no one is going to give you the code for this, and I'm sure that you don't want us to, but rather you just want help on a step that you're stuck on. So, what have you tried and how is it not working? Or failing that, exactly what step has you stumped?
Hi,
First of all, you just have to think about the problem and how to reach it. I'll give a hint using this questions.
what separates words? [String s = "Hello World, my name is cosmicCode";].
what separates these words in s ?
hope you got the idea.
Well, you want to make a string out a certain number of letters in the text file, for example you can check if it appears in one row by saving that row of text as let's say String s1 and compare it to a specified string (for example String s2= "hello"). Then you'd check if they are equal in something like:
String s1; String s2 = "hello"; int numberOfTimes; //Variable that contains the number of times s1 contains s2 if(s1.containsIgnoreCase(s2)==true{ //If s1 contains s2, IgnoreCase is optional but handy if you don't want it to be case-sensitive numberOfTimes++; }
And of course keep replacing s1 with the next set of letters, have luck!