Objective-C String Concatenation


/ Published in: Objective C
Save to your folder(s)

This is all about appending strings.


Copy this code and paste it in your HTML
  1. /* append to a mutable string */
  2. NSMutableString *aString = [[NSMutableString alloc] initWithString:@"If you don't eat your meat"];
  3. [aString appendString:@" you can't have any pudding."];
  4.  
  5. NSMutableString *bString1 = [[NSMutableString alloc] initWithString:@"We don't need"];
  6. NSMutableString *bString2 = [[NSMutableString alloc] initWithString:@"no education."];
  7. [bString1 appendFormat:@" %@", bString2];
  8.  
  9. /* concatenate 2 strings to make a 3rd */
  10. NSString *string1 = @"This is";
  11. NSString *string2 = @" a test.";
  12. NSString *string3 = [string1 stringByAppendingString:string2];
  13.  
  14. /* assigning an appended string back to itself */
  15. NSString *string1 = @"This is";
  16. NSString *string2 = @" a test.";
  17. string1 = [string1 stringByAppendingString:string2];

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.