文章来源: http://blog.sina.com.cn/s/blog_6b1e4a0601019pib.html
在ObjectiveC中NSString中有一个 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);
输出结果:
2013-04-12 10:31:48.213 String[2171:303] 123,465
下面这种方式是错误的:
str = [NSString stringWithFormat:@"123",@"456"];
NSLog(@"%@",str);
输出结果:
2013-04-12 10:35:34.043 String[2209:303] 123
str = [NSString stringWithFormat:@"%@,%@",@"123",@"456"];
NSLog(@"%@",str);
输出结果:
2013-04-12 10:42:39.541 String[2229:303] 123,456