开发者

Searching NSString Cocoa?

开发者 https://www.devze.com 2022-12-26 13:24 出处:网络
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\"?

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

精彩评论

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