//判断是否是纯字母
- (BOOL)isPureCharacters:(NSString *)string{
string = [string stringByTrimmingCharactersInSet:[NSCharacterSet letterCharacterSet]];
if(string.length > 0) {
return NO;
}
return YES;
}
//判断是否是纯数字
- (BOOL)isPureNum:(NSString *)string{
string = [string stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]];
if(string.length > 0) {
return NO;
}
return YES;
}
//判断是否包含连续的数组或字母,yes为包含
- (BOOL)rangeString:(NSString *)string {
BOOL result = NO;
for (int i = 0; i < string.length; i++) {
if (string.length - i < 4 ) {
break;
}
NSString *newStr = [string substringWithRange:NSMakeRange(i, 4)];
if ([self isPureCharacters:newStr] || [self isPureNum:newStr]) {
NSLog(@”%@”,newStr);
result = YES; break;
}
}
return result;
}
//是否是全中文
-(BOOL)isChinese
{
NSString *match = @”(^[\u4e00-\u9fa5]+$)”;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@”SELF matches %@”, match];
return [predicate evaluateWithObject:self];
}
//是否包含中文
-(BOOL)includeChinese
{
for(int i=0; i< [self length];i++)
{
int a =[self characterAtIndex:i];
if( a >0x4e00&& a <0x9fff){
return YES;
}
}
return NO;
}