Reputation: 773
I am trying to to do the following (psuedo)
NSString *variable = 'Name';
NSString *newString = @"Hello, " + variable + @" blah blah";
It would appear it is not as simple as the above! Any help?
Thanks
Upvotes: 4
Views: 9652
Reputation: 8905
NSString *str = @"Hello, ";
str = [str stringByAppendingString:variable];
str = [str stringByAppendingString:@" blah blah"];
If you prefer it as one line statement
NSString *str = [[@"Hello, " stringByAppendingString:variable] stringByAppendingString:@" blah blah"];
Swift
var str = "Hello, " + varaible + "blah blah"
OR
var str = "Hello, \(variable) blah blah"
Upvotes: 9
Reputation: 7048
NSString *newString = [NSString stringWithFormat:@"Hello, %@ blah blah", variable];
Upvotes: 4