Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine two NSString?

Tags:

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.

like image 308
adrian Avatar asked Sep 28 '11 08:09

adrian


People also ask

How to concatenate NSString in Objective C?

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.

How to append NSString?

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.

What is NSString?

A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.

How do I get substring in Objective C?

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.


2 Answers

To get what you want you can use

NSString *coordinates = [NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];
like image 72
hypercrypt Avatar answered Dec 24 '22 05:12

hypercrypt


Just use stringWithFormat method

[NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];
like image 34
EXC_BAD_ACCESS Avatar answered Dec 24 '22 03:12

EXC_BAD_ACCESS