4

我正在尝试执行以下操作(伪)

NSString *variable = 'Name'; 
NSString *newString = @"Hello, " + variable + @" blah blah";

看来它并不像上面的那么简单!有什么帮助吗?

谢谢

4

2 回答 2

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"

或者

var str = "Hello, \(variable) blah blah"
于 2012-07-07T15:10:28.483 回答
3
NSString *newString = [NSString stringWithFormat:@"Hello, %@ blah blah", variable];
于 2012-07-07T15:15:15.610 回答