iPhone Objective-C Concatenate multiple strings

November 10, 2009 § Leave a comment

Method 1: Add two strings together by using stringByAppendingString: method

NSString *string1 = @”Hello”;
NSString *string2 = @”World”;
NSString *entireString;
entireString = [string1 stringByAppendingString:string2];

Method 2:

NSString *string1 = @”This”;
NSString *string2 = @”is”;
NSString *string3 = @”a”;
NSString *string4 = @”test”;
NSString *entireString = [NSString stringWithFormat:@”%@ %@ %@ %@”, string1, string2, string3, string4];

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading iPhone Objective-C Concatenate multiple strings at Web Builders.

meta

%d bloggers like this: