标签:
1 /** 2 * NSString字符串常用操作 3 * initWithFormat:构造方法 4 * initWithUTF8String:将C字符串转换成OC字符串 5 */ 6 #import <Foundation/Foundation.h> 7 8 int main(int argc, const char * argv[]) { 9 @autoreleasepool { 10 11 char *str1="Hello str1";//C语言字符串 12 NSLog(@"%s",str1);//打印结果:Hello str1 13 14 NSString *str2=@"Hello str2";//OC中字符串 15 NSLog(@"%@",str2);//打印结果:Hello str2 16 17 //initWith... 构造方法 18 NSString *str3=[[NSString alloc]initWithFormat:@"Hello str3"]; 19 NSLog(@"%@",str3);//打印结果:Hello str3 20 21 //initWithFormat... 格式化字符串 22 NSString *str4=[[NSString alloc]initWithFormat:@"我是第%d个字符串str4",4]; 23 NSLog(@"%@",str4);//我是第4个字符串str4 24 25 //将C语言字符串转换为OC字符串 26 NSString *str5=[[NSString alloc]initWithUTF8String:"Hello str5"]; 27 NSLog(@"%@",str5);//打印结果:Hello str5 28 29 } 30 return 0; 31 }
标签:
原文地址:http://www.cnblogs.com/studyrecord/p/4824027.html