Hi
Can anyone let me know how to count the number of words in a file for example "hello" in a file
Thanks
Raj
Printable View
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:
Code :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!