NSString字符串的长度计算,今天写到这,顺便给大家也看看
- #import <Foundation/Foundation.h>
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
-
- //计算NSString 字符串的长度
- //1)字符串是纯英文的
- NSString *s1 = @"hello";
- NSUInteger len = [s1 length];
- NSLog(@"len = %ld",len);
-
- //2)字符串是纯中文的
- //OC字符串中,中英文都是一个字符
- NSString *s2 = @"碟中谍";
- len = [s2 length];
- NSLog(@"len = %ld",len);
-
- //3)中英文混合
- NSString *s3 = @"碟中谍five";
- len = [s3 length];
-
- NSLog(@"len = %ld",len);
- }
- return 0;
- }
复制代码
|
|