How do I concatenate to NSStrings
together in Objective C?
views:
576answers:
2
+2
A:
If you have a mutable string then you can do:
NSMutableString* someString = [NSMutableString stringWithString: @"Hello"];
[someString appendString: @", world!"];
For example. Be more specific if this is not the answer you are looking for.
St3fan
2010-02-10 02:06:13
+7
A:
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.
Lawrence Johnston
2010-02-10 02:18:05