Objective C - How to concatenate an entire array of strings?

Objective CNsstring

Objective C Problem Overview


I am an Objective C newbie. I want to write a method that takes in an array of strings and returns a concatenated string, with a comma (,) in between each string. So if an array is {a b c d}, I want to return a,b,c,d.

What is the easiest way to do that?

Objective C Solutions


Solution 1 - Objective C

There are many ways to do it, the simplest being

[yourArray componentsJoinedByString: @","]

Solution 2 - Objective C

Use NSArray's componentsJoinedByString: method.

NSArray *strings = ...;
NSString *combined = [strings componentsJoinedByString:@","];

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSuchiView Question on Stackoverflow
Solution 1 - Objective Cuser747858View Answer on Stackoverflow
Solution 2 - Objective CughoavgfhwView Answer on Stackoverflow