ios 如何判断字符串含有中文字符?

NSString *text = @"i'm a 苹果。...";
int length = [text length];

for (int i=0; i<length; ++i)
{
NSRange range = NSMakeRange(i, 1);
NSString *subString = [text substringWithRange:range];
const char *cString = [subString UTF8String];
if (strlen(cString) == 3)
{
NSLog(@"汉字:%s", cString);
}

NSString  *str = @ "i'm a 苹果。..." ;
for ( int  i=0; i< [str length];i++){
int  a = [str characterAtIndex:i];
if ( a > 0x4e00 && a < 0x9fff)
NSLog (@ "汉字" );
}
NSString  *str = @ "i'm a 苹果。..." ;
for ( int  i=0; i< [str length];i++){
int  a = [str characterAtIndex:i];
if ( a > 0x4e00 && a < 0x9fff)
NSLog (@ "汉字" );
}
 
NSString  *str = @ "i'm a 苹果。..." ;
for ( int  i=0; i< [str length];i++){
int  a = [str characterAtIndex:i];
if ( a > 0x4e00 && a < 0x9fff)
NSLog (@ "汉字" );
}

你可能感兴趣的:(ios)