Lil*_*ard 36
你试图找到它是否包含至少一个(或)?你可以使用-rangeOfCharacterFromSet::
NSCharacterSet *cset = [NSCharacterSet characterSetWithCharactersInString:@"()"];
NSRange range = [mystr rangeOfCharacterFromSet:cset];
if (range.location == NSNotFound) {
// no ( or ) in the string
} else {
// ( or ) are present
}
Run Code Online (Sandbox Code Playgroud)
dlo*_*omb 15
如果给定的字符串包含给定的char,则以下方法将返回Yes
-(BOOL)doesString:(NSString *)string containCharacter:(char)character
{
return [string rangeOfString:[NSString stringWithFormat:@"%c",character]].location != NSNotFound;
}
Run Code Online (Sandbox Code Playgroud)
您可以按如下方式使用它:
NSString *s = @"abcdefg";
if ([self doesString:s containCharacter:'a'])
NSLog(@"'a' found");
else
NSLog(@"No 'a' found");
if ([self doesString:s containCharacter:'h'])
NSLog(@"'h' found");
else
NSLog(@"No 'h' found");
Run Code Online (Sandbox Code Playgroud)
输出:
2013-01-11 11:15:03.830 CharFinder [17539:c07]'a'发现
2013-01-11 11:15:03.831 CharFinder [17539:c07]没有找到'h'
| 归档时间: |
|
| 查看次数: |
21289 次 |
| 最近记录: |