java - How to find occurrence of a string in another string where it's not embedded into another word? -
I am trying to create a static method "indexOfKeyword" and return an index for a string where string is the other word Has not been embedded in. If there is no such incident then -1 will return. For example, string s = "In Florida, snowshoes do not create any interest."; String keyword = "no"; This will return 31. I think the only problem is not to find the next occurrence of the string keyword. What I've done so far: Public static integeroffkeyword (string s, string keyword) {s = s.toLowerCase (); Keyword = keyword.toLowerCase (); Int startIdx = s.indexOf (keyword); While (startIdx> = 0) {string = ""; = "" String after; If (startIdx> 0) {before ssubstring (startIdx - 1, startIdx); } Int endIdx = startIdx; If (endIdx & lt; s.length ()) followed by {s.sstring (startIdx + keyword.length (), startIdx + keyword.length () + 1); } If (((before ((before () (= "A") gt0 = amp; amp; amp; before.compareTo (...