您刚刚开始学习这门语言,更多的是javascript / PHP家伙......
我似乎无法弄清楚正确的语法,在搜索了互联网以获得直接的答案或解释后,我决定打扰你SOF社区:
这就像我希望它一样有效:
self.displaysTheStack.text = [self.displaysTheStack.text stringByAppendingString:@" "];
self.displaysTheStack.text = [self.displaysTheStack.text stringByAppendingString:operation];
self.displaysTheStack.text = [self.displaysTheStack.text stringByAppendingString:@" "];
我想知道我是否可以用更少的行来做同样的事情:
NSString *displayTheArrayText = [NSString stringWithFormat:@" ",operation,@" "];
self.displaysTheStack.text = [self.displaysTheStack.text stringByAppendingString:displayTheArrayText];
当我这样做的时候,我得到了两个@“”(空格)但是“操作”没有显示出来:为什么以及如何正确地编写后一个命令?
答案 0 :(得分:2)
stringWithFormat:
使用与C-style formats
NSString *displayTheArrayText = [NSString stringWithFormat:@" %@ ",operation];
答案 1 :(得分:1)
self.displaysTheStack.text = [NSString stringWithFormat:@"%@ %@ ", self.displaysTheStack.text, operation];
可替换地:
NSMutableString *string = [NSMutableString stringWithString:self.displaysTheStack.text];
[string appendFormat:@" %@ ", operation];
self.displaysTheStack.text = string;