Found another solution with the help of the containsObject method:
[code]#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//read file 1
NSString *nameString = [NSString stringWithContentsOfFile:@"/usr/share/dict/propernames" encoding:NSUTF8StringEncoding error:NULL];
//read file 2
NSString *wordString = [NSString stringWithContentsOfFile:@"/usr/share/dict/words" encoding:NSUTF8StringEncoding error:NULL];
//Array für file 1
NSArray *names = [nameString componentsSeparatedByString:@"\n"];
//Array für file 2
NSArray *words = [wordString componentsSeparatedByString:@"\n"];
int count = 0;
for (NSString *n in words) {
if ([names containsObject:n]) {
NSLog(@"%@ is a duplicate.", n);
count++;
}
}
NSLog(@"Count: %d", count);
}
return 0;
}[/code]