您的位置:首页 > 其它

字符串判断

2016-05-25 10:55 295 查看
第一种判断不为空

- (BOOL)isBlankString:(NSString *)string {
if (string
== nil || string == NULL)
{
return YES;
}
else if ([string isKindOfClass:[NSNull class]])
{
return YES;
}
else if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0)
{
return YES;
}
return NO;
}
第二种判断不为空

-(BOOL)isEmptyString:(NSString *) str {
if (!str) {
return YES;
} else {
NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSString *trimedString = [str stringByTrimmingCharactersInSet:set];
if ([trimedString length] == 0) {
return YES;
} else {
return NO;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: