标签:
在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
@“456” 不会被输出;
以上代码可以改写成:
str = [NSString stringWithFormat:@"%@,%@",@"123",@"456"];
NSLog(@"%@",str);
输出结果:
2013-04-12 10:42:39.541 String[2229:303] 123,456
标签:
原文地址:http://www.cnblogs.com/littlewrong/p/4909006.html