Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to check whether a string containing some word

807607Nov 1 2006 — edited Nov 1 2006
Can u tell me how to check whether a string containing some word.

eg.
This is a ball.

I want to check wheter this string contain word 'ball'.
how to write the code?

I have to to write the code but it cannot go to the if (previous.contains("ball")) statement. I also try method matches() and endWith() but also cannot. I use endWith because the word i want to check is the end of the string. Did I use the wrong method?

while (iter.isValid()) {
    		
      		FeatureStructure fs = iter.get();
      		if (fs.getType().getName().equals("com.ibm.uima.examples.tokenizer.Sentence")){
      	    	if (fs instanceof AnnotationFS) {
      	    		
          			AnnotationFS annot = (AnnotationFS)fs;
 
    	      		String coveredText = annot.getCoveredText();
    	      		if (previous.contains("ball"))
    	      			System.out.println("hit\n");
 
      	      		 	sentenceCount = sentenceCount + 1;
      	
      	        		previous = coveredText;
      	        		
      	    	}
 
	      		iter.moveToNext();
      		}
      		else
      			iter.moveToNext();
    	}
    	sentenceCount = 0;
  	}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 29 2006
Added on Nov 1 2006
5 comments
297 views