我正在尝试执行以下操作(伪装)
NSString *variable = 'Name';
NSString *newString = @"Hello, " + variable + @" blah blah";
看起来它并不像上面那么简单!有什么帮助吗?
由于
答案 0 :(得分:9)
NSString *str = @"Hello, ";
str = [str stringByAppendingString:variable];
str = [str stringByAppendingString:@" blah blah"];
如果您更喜欢它作为一行声明
NSString *str = [[@"Hello, " stringByAppendingString:variable] stringByAppendingString:@" blah blah"];
<强>夫特强>
var str = "Hello, " + varaible + "blah blah"
OR
var str = "Hello, \(variable) blah blah"
答案 1 :(得分:3)
NSString *newString = [NSString stringWithFormat:@"Hello, %@ blah blah", variable];