//判断字符串是否是由数字组成
- (BOOL)stringIsNum:(NSString *)str
{
NSString *regex =@"[0-9]*";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if ([pred evaluateWithObject:str]) {
return YES;
}
return NO;
}
//判断字符串是否是由字母组成
- (BOOL)stringIsLetter:(NSString *)str
{
NSString *regex =@"[a-zA-Z]*";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if ([pred evaluateWithObject:str]) {
return YES;
}
return NO;
}
//判断字符串是否是由汉字组成
- (BOOL)stringIsChinese:(NSString *)str
{
NSString *regex = @"[\u4e00-\u9fa5]+";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if ([pred evaluateWithObject:str]) {
return YES;
}
return NO;
}
ios_字符串判断
最新推荐文章于 2020-09-08 10:16:15 发布