NSString *userIdStr=@“a&*林”;
int utfCode = 0;
void *buffer = &utfCode;
NSRange range = NSMakeRange(userIdStr.length - 1, 1);
NSString *word = [userIdStr substringWithRange:range];
BOOL b = [word getBytes:buffer maxLength:2 usedLength:NULL encoding:NSUTF16LittleEndianStringEncoding options:NSStringEncodingConversionExternalRepresentation range:range remainingRange:NULL];
if (b && (utfCode >= 0x4e00 && utfCode <= 0x9fa5)) {
NSLog(@"it is chinese,%@", word);
}else{
isChecked = NO;
errorMessage = @"用户名必须为汉字";
}
网友评论