I want to place a string within a string. Basically in pseudo code:
"first part of string" + "(varying string)" + "third part of string"
How can I do this in objective-c? Is there a way to easily concatenate in obj-c? Thanks!
Yes, do
NSString *str = [NSString stringWithFormat: @"first part %@ second part", varyingString];
For concatenation you can use stringByAppendingString
NSString *str = @"hello "; str = [str stringByAppendingString:@"world"]; //str is now "hello world"
For multiple strings
NSString *varyingString1 = @"hello"; NSString *varyingString2 = @"world"; NSString *str = [NSString stringWithFormat: @"%@ %@", varyingString1, varyingString2]; //str is now "hello world"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With