Check to see if a String contains Another String

I have a device that returns a string with some info. I am trying to see if the string contains a certain substring. It doesn’t always occur at the same place in the string, so doing it by string position won’t work.

I tried string.contains(string) but that gives me an error.

Is there some way I can do this?


int indexOf(String str)
Str – The string to search for

Return Value

Returns the index within this string of the first occurrence of the specified substring. If it does not occur as a substring, -1 is returned.


Finally got back around to this. Thank you for your suggestions. As it turned out I had an error in my original statement. The error message was so crptic I wasn’t seeing it. So I corrected that and now the contains works fine.

Thanks again for the suggestion.