Results 1 to 9 of 9
Thread: homework help/ String Searcher
- 12-03-2008, 05:05 AM #1Member
- Join Date
- Dec 2008
- Rep Power
homework help/ String Searcher
Here is my assignment:
This program asks for a sentence and a search word. It prints the number of times the search word appears exactly in the sentence, and the number of times the search word appears as part of another word.
An example would be "Madam, I'm Adam" search word: adam.
So far I've written the program so that it asks the user for the sentence and search word, and then converts everything to lower case. I'm having trouble with the counts though. I've been looking through the Lang book and have found a letter counter and trying to see if I can manipulate it to look like my search word instead, but so far have failed.
Does anyone know how to count the number of times the word appears exactly and as part of another word? I'm hoping to get this finished for tomorrow morning.
Last edited by safecracker; 12-03-2008 at 05:14 AM.
- 12-03-2008, 05:14 AM #2Senior Member
- Join Date
- Sep 2008
- Rep Power
You can easily iterate through the sentence to check for a substring. Java provides a lot of tools in the String class that will help you out in achieving this.
emceenugget is right on the money. I'll try to give you a head start by posting a link to the String API. Read through this and you'll find several methods worth trying out:
String (Java Platform SE 6)
- 12-04-2008, 01:35 AM #4
I think you might also want to take a look at StringTokenizer if you haven't already.miss.meli (-.-)zzZZ
- 12-04-2008, 05:58 AM #5
I don't think StringTokernizer is a good choice for this. Regular expressions are the best, in near future StringTokernizers can be deprecated. Actually we discuss about this several times in our community.
- 12-04-2008, 06:27 AM #6
- 12-04-2008, 06:32 AM #7
In simple word, some method are not in implementation. Can cause several issues, like memory crash and so on. What Sun do is, they introduce new implements for that method and the existing one named as deprecated, means Suns' strongly to advice not to use and use the new one.
- 12-04-2008, 06:38 AM #8
Oh okay, that makes sense.miss.meli (-.-)zzZZ
- 12-04-2008, 06:41 AM #9
- By Indulgence in forum New To JavaReplies: 1Last Post: 11-03-2008, 03:48 AM
- By robrobrob in forum New To JavaReplies: 4Last Post: 10-17-2008, 05:24 AM
- By JavaNewbie0000 in forum New To JavaReplies: 2Last Post: 07-31-2008, 04:06 PM
- By integralli in forum Threads and SynchronizationReplies: 6Last Post: 06-21-2008, 05:34 PM
- By alcohole4life in forum New To JavaReplies: 1Last Post: 05-23-2008, 05:18 PM