Skip to Main Content

New to Java

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!

Finding a Word in a sentence (Word doesn't matter what case it is)

807597Mar 20 2005 — edited Mar 20 2005
Greetings,


I am trying to find a method that would find a word in a sentence. I know that if you do sentence.indexOf("word"), you could tell where the word "word" is in the text. But what if the sentence is:

The Word is the way.

If I did sentence.indexOf("word"), it would return a -1, because "word" is not in the sentence. I can't just do sentence.indexOf("Word") because the user could type in something like:

The WOrd is the way.

And it wouldn't find the letters. So how can I make a code that would find a word in a sentence, and that it doesn't matter what the case of the word is. Thanks.

--Arran G.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 17 2005
Added on Mar 20 2005
3 comments
107 views