How do I concatenate to NSStrings together in Objective C?
-
Are you asking how to concatenate two strings?Anon.– Anon.2010-02-10 02:03:35 +00:00Commented Feb 10, 2010 at 2:03
-
2Duplicate of stackoverflow.com/questions/589395/…Anurag– Anurag2010-02-10 02:06:29 +00:00Commented Feb 10, 2010 at 2:06
Add a comment
|
2 Answers
If the string is not mutable, you will instead want:
NSString *firstString = @"FirstString";
NSString *secondString = @"SecondString";
NSString *concatinatedString = [firstString stringByAppendingString:secondString];
// Note that concatinatedString is autoreleased,
// so if you may want to [concaticatedString retain] it.
For completeness, here's the answer for a mutable string:
NSMutableString *firstString = [NSMutableString stringWithString:@"FirstString"];
NSString *secondString = @"SecondString";
[firstString appendString:secondString];
// Note that firstString is autoreleased,
// so if you may want to [firstString retain] it.