iPhone Objective-C Concatenate Multiple Strings into a single URL

November 10, 2009 § Leave a comment

Method 1:
// Declare URL parameters
NSString *URL = @”http://www.xyz.com/api?”;
NSString *latitudeURL = @”latitude=”;
NSString *longitudeURL = @”&longitude=”;
NSString *altitudeURL = @”&altitude=”;
// Concatenate all the strings
NSString *entireURL = [NSString stringWithFormat:@”%@%@%@%@%@%@%@”, URL, latitudeURL, latitudeString, longitudeURL, longitudeString, altitudeURL, altitudeString];
NSLog(@”show:%@”, entireURL);

Method 2:

// Shortcut to concatenate all the strings
NSString *apiString = [NSString stringWithFormat:@”http://www.xyz.com/api?latitude=%@&longitude=%@&altitude=%@”, latitudeString, longitudeString, altitudeString];
NSLog(@”show:%@”, apiString);

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 into a single URL at Web Builders.

meta

%d bloggers like this: