Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate String in String Objective-c

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!

like image 331
jsttn Avatar asked Aug 15 '12 15:08

jsttn


1 Answers

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" 
like image 95
Dustin Avatar answered Sep 19 '22 01:09

Dustin