I would like to compare different strings and neither isEqualToString nor rangeOfString can, in my case, do the work apparently.
For example I have the following strings:
s1 = Hello World
s2 = World
I now would like to compare these and that works fine with rangeOfString, return true, the issue is when i then compare for example this:
s1 = helloworldhello
s2 = world
this should in my case return false but rangeOfString will return true.
The condition are the following:
I want to find exact matches.
I want to find similar strings for example "Anna" should be equal to "Hanna Anna"
I do not want to find half words for example "Ann" should not be equal to "Anna"
I do not want to find a part of a word for example "nn" should not be equal to "Anna"
In the case you are looking for “World” as a single word use range with a regular expression:
NSLog output:
match: 1
NSLog output:
match: 0
NSLog output:
match: 1
NSLog output:
match: 0
NSLog output:
match: 0
The backslash-b means a word boundary and the backslash must be escaped.