Concatenate string in Objective-C
Unfortunately, this is not as straight forward as it seems it should be. This really comes down to roughly two approaches in my opinion:
stringByAppendingString approach:
NSString *robot= @"Ronnie"; NSString *robotname = [robot stringByAppendingString:@" is the name of a robot."];
strigWithFormat approach:
NSString *robot= @"Ronnie"; NSString *robotname= @" is the name of the a robot."; NSString *robotknowledge = @" knows eight languages."; [NSString stringWithFormat:@"%@/%@/%@", robot, robotname, robot, robotknowledge];
References
StackOverflow, http://stackoverflow.com/questions/510269/how-do-i-concatenate-strings-in-objective-c
cocoadevcentral.com, “Learn Objective-C”, http://cocoadevcentral.com/d/learn_objectivec/
Posted on June 20, 2011, in Programming & Development and tagged append, cocoa, concat, concatenate, format, ios, iphone, macosx, objc, objective c, string, stringByAppendingString, stringwithformat. Bookmark the permalink. Leave a comment.
Leave a comment
Comments 0