Reputation: 4594
I have the following two NSString
:
NSString *latitudeString, *longitudeString;
latitudeString = @"50.1338";
and
longitudeString = @"8.91583";
What I want to obtain is a NSString that looks like this: 50.1338,8.91583.
How do I obtain that?Thanks
IMPORTANT: The values I showed are only for the purpose of better understanding, ussually latitudeString
and longitudeString
have random values.
Upvotes: 20
Views: 32244
Reputation: 100652
A thousand years late:
[latitudeString stringByAppendingFormat:@",%@", longitudeString]
Would slightly reduce runtime parsing costs and, historically, would have given you greater type safety (before the compiler checked type strings). So some of us old timers got used to it and still mentally make the fairly feeble performance argument to justify what's comfortable.
[@[latitudeString, longitudeString] componentsJoinedByString:@","]
May also be preferable if you'd rather raise an exception upon one string being missing than silently produce something nonsensical.
Upvotes: 5
Reputation: 8163
[NSString stringWithFormat:@"%@,%@",latitudeString,longitudeString];
Upvotes: 1
Reputation: 15376
To get what you want you can use
NSString *coordinates = [NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];
Upvotes: 61
Reputation: 51
Maybe it was better:
[NSString stringWithFormat:@"%.4f,%.4f",[latitudeString floatValue],[longitudeString floatValue]];
Upvotes: 4
Reputation: 3809
Try this
NSString *combine = [NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];
Upvotes: 4
Reputation: 38223
String* coord = [NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];
Upvotes: 2
Reputation: 2707
Just use stringWithFormat method
[NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];
Upvotes: 8