第一种:
NSArray *array = [NSArray arrayWithObjects:@"Hello",@" ",@"world", @"!", nil]; NSString *printStr = @""; for(int i = 0; i < [array count]; i++){ printStr = [printStr stringByAppendingFormat:@"%@", [array objectAtIndex:i]]; } NSLog(@"第一种方法%@", printStr);
第二种:
NSArray *array = [NSArray arrayWithObjects:@"Hello",@" ",@"world", @"!", nil]; NSMutableString *printStr2 = [[NSMutableString alloc] init]; for(int i = 0; i < [array count]; i++){ [printStr2 appendFormat:@"%@", [array objectAtIndex:i]]; } NSLog(@"第二种方法%@", printStr2);
输出结果:
2015-06-01 21:33:52.964 String追加字符串[28638:601104] 第一种方法Hello world! 2015-06-01 21:33:52.965 String追加字符串[28638:601104] 第二种方法Hello world!