containsString
最近被项目赶着走,总算体会到了新人不容易唉,压力一层层的来,还有其他的一些杂七杂八的事情要整,每天的时间都是觉得不够用。项目权限控制,然而根据端口编号进行判断,又特么是一长串的字符串,无解,只能是查看是否包含在里面进行判断处理。真的是很恶心···
if (!self.curAccount.isManager) {
if (![self.curAccount.authCode containsString:@"110"]) {
[MBProgressHUD showOnlyText:@"您暂无此权限"];
NSLog(@"没有这个权限");
} else {
[self reload];
NSLog(@"包含该字段,有这个权限");
}
} else {
[self reload];
}
//上面这个方法是在iOS8之后才有的
NSString *string = @"0301";
//字条串是否包含有某字符串
if ([string rangeOfString:@"0311"].location == NSNotFound) {
NSLog(@"string不存在该功能编码");
} else {
NSLog(@"string包含该功能编码");
}
另外还有两个比较特殊的情况,就是在开头结尾的
//字条串开始包含有某字符串
NSString *string = @"hello world";
if ([string hasPrefix:@"hello"]) {
NSLog(@"string 包含 hello");
} else {
NSLog(@"string 不存在 hello");
}
//字符串末尾有某字符串;
if ([string hasSuffix:@"world"]) {
NSLog(@"string 包含 bitch");
} else {
NSLog(@"string 不存在 bitch");
}