开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜