Searching NSString Cocoa?
I have a string of letters and I want to search it for a specific letter.
NSString *word = @"word";
How would I开发者_JAVA百科 find out if the string contained a letter "w"?
Thanks
You could do it using rangeOfString:
NSString *word = @"word";
if ([word rangeOfString:@"w"].location == NSNotFound)
NSLog(@"word does not contain w");
else
NSLog(@"word contains w");
return [word rangeOfString:@"w"].location != NSNotFound;
return ([word rangeOfString:@"w"].location != NSNotFound);
精彩评论