| | |
Best Way to Check for same Word in string?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2008
Posts: 28
Reputation:
Solved Threads: 0
i have a similar problem where i have to find the number of occurences of a particular word from a sentence, i tried the code but it even counts the words which have those alphabets partly. can anyone help me with this
Java Syntax (Toggle Plain Text)
import java.lang.String; public class StringCount2 { public static void main(String args[]) { String searchFor = "is"; String base = "This is object oriented programming language "; int len = searchFor.length(); //System.out.println( "length of object =" +len); int result = 0; if (len > 0) { int start = base.indexOf(searchFor); // System.out.println("index of object =" + start); while (start != -1) { result++; start = base.indexOf(searchFor, start+len); } } System.out.println(result); } }
this thread is two years old, why not post in another topic? many people also frown upon thread hijacking
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
![]() |
Similar Threads
- extract token(word) from string (C++)
- Finding # Occurences of Each Word in String (C)
- Recognize the word in a string (JavaScript / DHTML / AJAX)
- Display Longest and Shortest Word in a String (C++)
- check number is string (C)
Other Threads in the Java Forum
- Previous Thread: Main method parameter
- Next Thread: problem regarding buttons and graphics
Views: 5695 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addball addressbook android api append apple applet application arguments array arrays automation binary bluetooth button chat class classes client code component css csv database draw eclipse ee error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me java javaarraylist javaprojects jmf jni jpanel julia jvm key linux list loan loop map method methods mobile netbeans newbie number object oracle output panel phone print problem program programming project recursion reporting robot scanner screen se server service set size sms socket software sort sql stream string swing test threads time transfer tree ubuntu windows wrong






