create
#progma mark create NSString
void stringCreate(){
//char *s="A String";->c
NSString *str1[email protected]"A String!"; //const, no memory management
NSString *str2=[[NSString alloc]init];
[email protected]"A String!";
[str2 release];
NSString *str3=[[NSString alloc]initWithString:@"A String!"];
[str3 release];
NSString *str4=[[NSString alloc]initWithUTF8String:"A String!"];
// 传入一个C语言的字符串
[str4 release];
int i=10;
float height=18.0f;
NSString *str5=[[NSString alloc]initWithFormat:@"My age is %i and height is%.2f",age,height];
NSLog(@"str5 is %@",str5);
[str5 release];
}
//基本上以上方法都有对应的静态方法
//str3=nil;
时间: 2024-10-05 15:53:30