I know that I can use the statement: [string1 rangeOfString:compareString].location!=NSNotFound to check if a string contains a substring. However, I was wondering how specific this comparison was. If I am checking for the string “birthday” and the string was actually “birthdayy”, would it still come up as True?
I know that I can use the statement: [string1 rangeOfString:compareString].location!=NSNotFound to check if a
Share
The
rangeOfString:methods look for substrings within a string. The string “birthday” is a substring of “birthdayy”, so your expression will returnYES.If you want to match whole words only, you need to look at word boundaries: break up the string into an array with
componentsSeparatedByString:and test each element, or use a regular expression.