I would like to know a simple algorithm to determine if a string contains an exact sentence or word.
I'm not looking for:
string.contains(anotherString)
That's why:
let string = "I know your name"
string.contains("you")
In the above example, it returns true, because if find is "you"in the word "your". I want a method that will return false in this state.
For instance:
let string = "I am learning Swift"
string.contains(exact: "learn")
The method contains(exact:)will return false, since it is "learn"not equal"learning"
Another example:
let string = "Healthy low carb diets"
string.contains(exact: "low carb diet")
What algorithm will get this result in Swift 3? Or is there a predefined method for this?
source
share