Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-30-2010, 09:41 PM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 48
nacho3d is on a distinguished road
Default String concat?

I'm sure that this was questioned thousand of times, and i did search on Google before posting this question.

But, my answer is, wich is the easiest way to concat strings.

For example, i have to build an url taking values of my app to pass as parameters in the url.

For example, the url that i have to request is:

http://myserver.com/myaction

and then i have to create something like this:

http://myserver.com/myaction?param1=...&param2=value2

taking those values from my app.

What i saw is something like this:

NSString *uri = @"http://myserver.com/myaction";
NSString *concatenate = [uri stringByAppendingString: @"?param1="];
NSString *concatenate1 = [concatenate stringByAppendingString: @"value1"];

But i really don't see it nice. Is there a nicer method to concat strings? Some operator like the one in java, in php, etc?
nacho3d is offline   Reply With Quote
Old 08-30-2010, 09:53 PM   #2 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 11
psycorpse is on a distinguished road
Default

Quote:
Originally Posted by nacho3d View Post
I'm sure that this was questioned thousand of times, and i did search on Google before posting this question.

But, my answer is, wich is the easiest way to concat strings.

For example, i have to build an url taking values of my app to pass as parameters in the url.

For example, the url that i have to request is:

http://myserver.com/myaction

and then i have to create something like this:

http://myserver.com/myaction?param1=...&param2=value2

taking those values from my app.

What i saw is something like this:

NSString *uri = @"http://myserver.com/myaction";
NSString *concatenate = [uri stringByAppendingString: @"?param1="];
NSString *concatenate1 = [concatenate stringByAppendingString: @"value1"];

But i really don't see it nice. Is there a nicer method to concat strings? Some operator like the one in java, in php, etc?
Not sure if it is the correct way however this is what I might do

NSString * uri = [NSString stringWithFormat:@"http://myserver.com/myaction?param1=%@param2%@", @"value1", @"value2"];

Something like that might work.
psycorpse is offline   Reply With Quote
Old 08-30-2010, 09:54 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 386
SoulRed12 is on a distinguished road
Default

NSString objects are immutable. That means, once you've created them, they CANNOT be changed in any way.

The only way to keep a single object (as opposed to creating new objects each with a string appended onto the last) is to use an NSMutableString and its -appendString method:

Code:
NSMutableString *uri = @"http://myserver.com/myaction";
[uri appendString:@"?param1="];
[uri appendString:@"value1"];
Keep in mind though, that if you want to use a formatted string you will have to use appendFormat: instead of appendString:.
SoulRed12 is offline   Reply With Quote
Old 08-31-2010, 06:32 AM   #4 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 11
psycorpse is on a distinguished road
Default

Quote:
Originally Posted by nacho3d View Post
I'm sure that this was questioned thousand of times, and i did search on Google before posting this question.

But, my answer is, wich is the easiest way to concat strings.

For example, i have to build an url taking values of my app to pass as parameters in the url.

For example, the url that i have to request is:

http://myserver.com/myaction

and then i have to create something like this:

http://myserver.com/myaction?param1=...&param2=value2

taking those values from my app.

What i saw is something like this:

NSString *uri = @"http://myserver.com/myaction";
NSString *concatenate = [uri stringByAppendingString: @"?param1="];
NSString *concatenate1 = [concatenate stringByAppendingString: @"value1"];

But i really don't see it nice. Is there a nicer method to concat strings? Some operator like the one in java, in php, etc?
I believe you can join the elements of an array but I don't think there is a concat() function.
psycorpse is offline   Reply With Quote
Old 08-31-2010, 07:44 AM   #5 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 48
nacho3d is on a distinguished road
Default

Thanks both

nacho3d is offline   Reply With Quote
Reply

Bookmarks

Tags
nsstring

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 353
6 members and 347 guests
dre, freewind, hain, HemiMG, lendo, Newbie123
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:00 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0