Skip to content

Instantly share code, notes, and snippets.

@tediscript
Created March 25, 2013 07:29
Show Gist options
  • Select an option

  • Save tediscript/5235459 to your computer and use it in GitHub Desktop.

Select an option

Save tediscript/5235459 to your computer and use it in GitHub Desktop.
NSString *string1 = @"This is";
NSString *string2 = @" a test.";
NSString *string3 = [string1 stringByAppendingString:string2];
// string3 is now @"This is a test." string1 and string2 are unchanged.
//You can also assign the new string back to string1:
NSString *string1 = @"This is";
NSString *string2 = @" a test.";
string1 = [string1 stringByAppendingString:string2];
// string1 is now @"This is a test."
//If you're using a NSMutableString, you can simply call the appendString method:
NSMutableString *string1 = [NSMutableString stringWithString:@"This is"];
NSString *string2 = @" a test.";
[string1 appendString:string2];
NSLog(@"string1: %@", string1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment