【学习笔记】【OC语言】NSString
1.字符串的快速创建
NSStirng *str = @“Hello”;
2.使用静态方法创建
3.使用%@输出字符串
NSString *name = @”dssf”;
NSLog(@“我的名字是%@”, name);
4.代码
1 #import <Foundation/Foundation.h> 2 3 @interface Person : NSObject 4 { 5 //char *_name; 6 NSString *_name; 7 } 8 @end 9 10 int main() 11 { 12 /* 13 // 最简单的创建字符串的方式 14 NSString *str = @"isdssf"; 15 16 char *name = "isdssf"; 17 18 19 NSLog(@"我在%@上课", str); 20 //NSLog(@"%s", name); 21 */ 22 23 int age = 15; 24 int no = 5; 25 NSString *name = @"哈哈jan"; 26 // length方法算的是字数 27 int size = [name length]; 28 29 NSLog(@"%d", size); 30 31 // 创建OC字符串的另一种方式 32 NSString *newStr = [NSString stringWithFormat:@"My age is %d and no is %d and name is %@", age, no, name]; 33 34 35 NSLog(@"---- %ld", [newStr length]); 36 37 return 0; 38 }