Skip to content

Instantly share code, notes, and snippets.

@asmallteapot
Created April 19, 2011 16:38
Show Gist options
  • Save asmallteapot/928734 to your computer and use it in GitHub Desktop.
Save asmallteapot/928734 to your computer and use it in GitHub Desktop.
Naïve fuzzy–matching of NSStrings.

Simple fuzzy–matching of NSStrings, ignoring case, diacritics, and position in the string being searched. Based on a blog post by @rwenderlich, Apple’s documentation, and banging my keyboard until it works.

NSString *text = @"Drinking espresso in a café owned by Māori carpenters.";
NSString *searchFor = @"ma";
NSRange range = [text rangeOfString:searchFor options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];
if(range.location != NSNotFound) {
// string found
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment