方法一:
- (BOOL)hasChinese:(NSString *)str {
for(int i=0; i< [str length];i++){
int a = [str characterAtIndex:i];
if( a > 0x4e00 && a < 0x9fff)
{
return YES;
}
}
return NO;
}
方法二:
- (BOOL)isHasChineseWithStr:(NSString *)strFrom {
for (int i=0; i<strFrom.length; i++) {
NSRange range =NSMakeRange(i, 1);
NSString * strFromSubStr=[strFrom substringWithRange:range];
const char *cStringFromstr = [strFromSubStr UTF8String];
if (strlen(cStringFromstr)==3) {
//汉字
return YES;
} else if (strlen(cStringFromstr)==1) {
//字母
}
}
return NO;
}
时间: 2024-11-08 22:40:57