Posted By

ryantxr on 05/29/13


Tagged

Objective-c iphone ios


Versions (?)

Objective-C String Concatenation


 / Published in: Objective C
 

This is all about appending strings.

  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  

You need to login to post a comment.