#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//计算NSString 字符串的长度
//1)字符串是纯英文的
NSString *s1 = @"ban";
NSUInteger len = [s1 length];
//2)字符串是纯中文
//OC字符串中中英文都是一个字符
NSString *s2 =@"班长的节操"; // 5
len = [s2 length];
//3)中英文混合
NSString *s3 = @"班长!";
len = [s3 length];
NSLog(@"len = %ld",len); //3
//在C语言UTF-8编码中一个汉字占用3个字节
char *s = "班长的节操!";
long len1 = strlen(s);
printf("len1 = %ld\n",len1); //3
}
return 0;
}
|
|