Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to compare to strings. But isEqualToString is not useful for me. Because i don't want them to be exactly same. ?f one of my strings is Lev Tolstoy and the other one is just Tolstoy; i want them to be matched. Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
127 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you always know the Substring you're looking for, try this (the order of the words doesn't matter, so even 'Tolstoy Lev' would match):

NSString *string = @"Lev Tolstoy";
if ([string rangeOfString:@"Tolstoy"].location == NSNotFound) {
  NSLog(@"string does not contain 'Tolstoy'");
} else {
  NSLog(@"string contains 'Tolstoy'!");
}

For more information about rangeOfString: take a look at Apples documentation for NSString

For more complex situations take a look at this: http://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28string_functions%29


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...