tags:

views:

70

answers:

3

I have a string of letters and I want to search it for a specific letter.

NSString *word = @"word";

How would I find out if the string contained a letter "w"?

Thanks

A: 
return [word rangeOfString:@"w"].location != NSNotFound;
KennyTM
+2  A: 

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");
DyingCactus
A: 
return ([word rangeOfString:@"w"].location != NSNotFound);
Paul Lynch