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

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

What is the easiest way to do this?

+46
objective-c nsstring
04 Oct 2018-11-22T00:
source share
2 answers

There are many ways to do this, the simplest

[yourArray componentsJoinedByString: @","] 
+124
04 Oct 2018-11-21T00:
source share

Use the NSArray componentsJoinedByString: method.

 NSArray *strings = ...; NSString *combined = [strings componentsJoinedByString:@","]; 
+17
04 Oct 2018-11-21T00:
source share



All Articles