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.
Created
April 19, 2011 16:38
-
-
Save asmallteapot/928734 to your computer and use it in GitHub Desktop.
Naïve fuzzy–matching of NSStrings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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