initWithFormat。。。stringWithFormat

1、initWithFormat是实例办法

只能经由过程 NSString* str = [[NSString alloc] initWithFormat:@"%@",@"Hello World"] 调用,然则必须手动release来开释内存资料

2、stringWithFormat是类办法

常见的输出方式:
NSString *height;
height = [NSString stringWithFormat:@"Your height is %d feet, %d inches.",5,11];
NSLog(@"%@",height);

输出结果:
2013-04-12 10:30:47.744 String[2161:303] Your height is 5 feet, 11 inches.


输出多个字符的方式(以两个字符为例):

NSString *str;
NSString *str1 = @"123";
NSString *str2 = @"465";
str = [NSString stringWithFormat:@"%@,%@",str1, str2];
NSLog(@"%@",str);

posted on 2016-04-16 14:15  小|晄  阅读(56)  评论(0编辑  收藏  举报

导航