Return to Snippet

Revision: 63678
at May 29, 2013 23:52 by ryantxr


Updated Code
/* append to a mutable string */
NSMutableString *aString = [[NSMutableString alloc] initWithString:@"If you don't eat your meat"];
[aString appendString:@" you can't have any pudding."];

NSMutableString *bString1 = [[NSMutableString alloc] initWithString:@"We don't need"];
NSMutableString *bString2 = [[NSMutableString alloc] initWithString:@"no education."];
[bString1 appendFormat:@" %@", bString2];

/* concatenate 2 strings to make a 3rd */
NSString *string1 = @"This is";
NSString *string2 = @" a test.";
NSString *string3 = [string1 stringByAppendingString:string2];

/* assigning an appended string back to itself */
NSString *string1 = @"This is";
NSString *string2 = @" a test.";
string1 = [string1 stringByAppendingString:string2];

Revision: 63677
at May 29, 2013 23:23 by ryantxr


Initial Code
/* append to a mutable string */
NSMutableString *aString = [[NSMutableString alloc] initWithString:@"If you don't eat your meat"];
[aString appendString:@" you can't have any pudding."];

/* concatenate 2 strings to make a 3rd */
NSString *string1 = @"This is";
NSString *string2 = @" a test.";
NSString *string3 = [string1 stringByAppendingString:string2];

/* assigning an appended string back to itself */
NSString *string1 = @"This is";
NSString *string2 = @" a test.";
string1 = [string1 stringByAppendingString:string2];

Initial URL

                                

Initial Description
This is all about appending strings.

Initial Title
Objective-C String Concatenation

Initial Tags
iphone, ios

Initial Language
Objective C