0

我试图在没有任何成功的情况下附加文本,直到我尝试了这个:

NSString *n_result = @"";
n_result = [n_result stringByAppendingString:[NSString stringWithFormat:@"The number "]];
    n_result = [n_result stringByAppendingString:[NSString stringWithFormat:@"%@ ", n_analyze]];
    n_result = [n_result stringByAppendingString:[NSString stringWithFormat:@", has "]];
    n_result = [n_result stringByAppendingString:[NSString stringWithFormat:@"%i ", steps]];
    n_result = [n_result stringByAppendingString:[NSString stringWithFormat:@"steps to reach 1"]];

问题是,必须有一种更简单的方法来做到这一点。但我不知道怎么做。谁能帮我这个?我一直在到处寻找如何“更好”地做到这一点。

4

2 回答 2

3

[NSString stringWithFormat:@"The number %@ , has %i steps to reach 1", n_analyze, steps]

于 2013-05-09T23:11:03.707 回答
3

是的,有一个稍微简单的方法。使用一个实例NSMutableString

NSMutableString *mutableString = [NSMutableString stringWithFormat:@"The number "];
[mutableString appendFormat:@"%@ ", n_analyze];

// etc.. 
于 2013-05-09T23:12:32.167 回答