Why does the words file on my computer contain all the names? And some are listed twice, “Woody” and then “woody”. Yvonne is a word? And so is Z? I’m matching 34368 entries:
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
//find names that match proper nouns /usr/shar/dict/words
NSString *namesString = [NSString stringWithContentsOfFile:@"/usr/share/dict/propernames"
encoding:NSUTF8StringEncoding
error:NULL];
NSArray *names = [namesString componentsSeparatedByString:@"\n"];
NSString *wordsString = [NSString stringWithContentsOfFile:@"/usr/share/dict/words"
encoding:NSUTF8StringEncoding
error:NULL];
NSArray *words = [wordsString componentsSeparatedByString:@"\n"];
int numberFound;
for(NSString *aName in names){
//NSLog(@"%@",aName);
for(NSString *aWord in words){
NSRange match = [aName rangeOfString: aWord options:NSCaseInsensitiveSearch ];
//NSLog(@"%@",aWord);
//this will match sub strings so also compare string length
if( match.location != NSNotFound && aName.length == aWord.length){
numberFound++;
NSLog(@"Match! Word: %@ Name: %@",aWord,aName);
}
}
}
NSLog(@"Name count: %i", (int)names.count);
NSLog(@"Total found: %i",numberFound);
}
return 0;
}
sample of words file data: