判断是否含有非法字符 yes 有 no没有
- (BOOL)JudgeTheillegalCharacter:(NSString *)content{
//提示 标签不能输入特殊字符
NSString *str =@"^[A-Za-z0-9\u4e00-u9fa5]+$";
NSPredicate* emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", str];
if (![emailTest evaluateWithObject:content]) {
return YES;
}
return NO;
}
得到中英文混合字符串长度(两种方法)
- (int)convertToInt:(NSString*)strtemp{
int strlength = 0;
char* p = (char*)[strtemp cStringUsingEncoding:NSUnicodeStringEncoding];
for (int i=0 ; i<[strtemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding] ;i++) {
if (*p) {
p++;
strlength++;
}else {
p++;
}
}
return strlength;
}
- (int)getToInt:(NSString*)strtemp{
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSData* da = [strtemp dataUsingEncoding:enc];
return [da length];
}