iOS 判断string 是否是纯汉字
NSString * isOk = [self isChinese:self.searchStr]?@"YES":@"NO";
isOK 如果是"YES" 则是纯汉字 反正则不是
#pragma mark 是否是纯汉字
- (BOOL)isChinese :(NSString *)str
{
NSString *match = @"(^[\u4e00-\u9fa5]+$)";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF matches %@", match];
return [predicate evaluateWithObject:str];
}
网友评论