I have a string...like "This is my new car .It is very good in use.it is very very expensive." I want to know ,that how many times a word "very" has come in this string.
Asked
Active
Viewed 277 times
-8
-
Welcome to StackOverflow! When asking a question, please be sure to include a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) of the code you are using. If you have not written any code yet, chances are good that the question is off-topic for this site. Make sure to do some research and try to solve the problem yourself first. Then, if you still have any specific (non-"give me the code") questions, post a [good question](http://stackoverflow.com/help/how-to-ask) and we will be happy to help you. – Mage Xy Jan 06 '16 at 16:09
-
What about words containing very? "This is my new birdcage, It is bigger than an avery," – Bathsheba Jan 06 '16 at 16:10
-
@NathanOliver I picked for OP. – erip Jan 06 '16 at 16:14
-
1Do your homeworks by yourself ... – amdev Jan 06 '16 at 16:19
1 Answers
0
Look at the substring method in java. That is what you need. The basic idea is to check for every word and in order to see that, grad each word from the sentence, you would use the substring method and then from there you can start comparing the word against which you are looking for.
- Use a loop to go through every single character.
- Check for the next empty character
- Form a word from where the previous non-empty character was till the empty character
- Check to see if the word matches what you are looking for. If it does then increment your match counter.
- You must also make sure you exit the loop once you hit the last character.
Hope this helps