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.
You use it with @"%@%@" to concatenate two strings, @"%@%@%@" to concatenate three strings, but you can put any extra characters inside, print numbers, reorder parameters if you like and so on.
Working with NSString. Instances of the class NSString are immutable – their contents cannot be changed. Once a string has been initialized using NSString, the only way to append text to the string is to create a new NSString object. While doing so, you can append string constants, NSString objects, and other values.
A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.
NSString *needle = [haystack componentsSeparatedByString:@":"][1]; This one creates three temporary strings and an array while splitting. All snippets assume that what's searched for is actually contained in the string. Ky.
To get what you want you can use
NSString *coordinates = [NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];
Just use stringWithFormat method
[NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With