i have a String s1. user is queried to enter a sub-String sSub. i need to see if sSub exists within s1. eg;, s1 = "JAVA programming is wonderful"; sSub = "AVA" if sSub exists in s1 return "TRUE else return false; result is boolean and MUST be case sensitive. i see lastIndexOf() and indexOf() but am really looking for something like anyIndexOf(). so how do you perform this little trick?
One way would be to move through the String checking the 3 character substring that begins in index 0, then the one that begins in index 1, then the one that begins in index 2, and so on. Another way would be to move through the String looking for the first letter of the substring, and if you find it, compare the next index in the string to the second character of the substring, and so on. There are lots of ways to do something like this. I hope one of these suggestions helps you get started. Thanks, Joe
Joined: Jul 21, 2003
What Joe has said is correct and can be considered as a solution, but reinventing the wheel is never a good idea.