Reputation: 6381
Like the title. How to combined multiple NSString
in Objective-C ?
NSString *SERVER_IP = @"123.45.678.123";
NSString *PORT = @"12345";
NSString *USER_ID = @"123123-123123-123-123-123123";
I want to combined the above String in to URL , and I try to use the following code. But it seems didn't work...
NSURL *url = [NSURL URLWithString:@"http://%@:%@/user/%@",SERVER_IP,PORT,USER_ID];
How to combined multiple NSString
in Objective-C ?
I am new to IOS...Thanks in advance.
Upvotes: 0
Views: 100
Reputation: 1519
You were almost right ! You should do it like this :
NSString *SERVER_IP = @"123.45.678.123";
NSString *PORT = @"12345";
NSString *USER_ID = @"123123-123123-123-123-123123";
NSString *URLString = [NSString stringWithFormat:@"http://%@:%@/user/%@",SERVER_IP,PORT,USER_ID];
NSURL *url = [NSURL URLWithString:URLString];
Upvotes: 4
Reputation: 82759
your coding is fine
NSString *SERVER_IP = @"123.45.678.123";
NSString *PORT = @"12345";
NSString *USER_ID = @"123123-123123-123-123-123123";
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%@/user/%@",SERVER_IP,PORT,USER_ID];];
u need to convert NSUrl
to NSString
NSString *myString = [url absoluteString];
Upvotes: 2